bugGNU Octave - Bugs: bug #63523, patch: input validation for cdata...

 
 

bug #63523: patch: input validation for cdata and facevertexcdata needs improvement

Submitter:  A.R. Burgers <arb>
Submitted:  Wed 14 Dec 2022 08:22:49 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 07 Mar 2024 04:59:06 PM UTC, comment #5: 

apparently the documented correct way to do CData with 1 RGB per face is :

D = permute([0 0.1 0.2; 0.3 0.4 0.5; 0.6 0.7 0.8; 0.9 1.0 0.0], [3 1 2])  # 1xNx3 array

both store the same in FaceVertexCData, but the above produces row vectors on each page in CData.  Both render the same.

Nicholas Jankowski <nrjank>
Group Member
Thu 07 Mar 2024 04:21:08 PM UTC, comment #4: 

now also seeing this note in graphics.in.h:

    // Matlab allows incoherent data to be stored into patch properties.
    // The patch should then be ignored by the renderer.


so it seems some lack of input validation might be intentional.  should at least review the compatibility of any GIGO fixes.

Nicholas Jankowski <nrjank>
Group Member
Thu 07 Mar 2024 03:33:27 PM UTC, comment #3: 

looking a little more at the different input handling cases in bug #65421, input validation for both CData and FaceVertexCData could be significantly improved.  FaceVertexCData catches a number of malformed entries, but not all. CData catches very few and produces odd color output as a result. I didn't test mismatches in vertex/face/point count for the different forms, but apparently that should be part of it too. 

copying the input checking from the other report below, and broadening the report title a bit.

6 vertex, 4 face, 2D patch:

close all;
P = [ 2.5, 7.5; 6.5, 7.0; 2.5, 5.5; 6.5, 6.0; 1.0, 6.5; 8.0, 6.5];
T = [5,  3,  1; 1,  4,  2; 1,  3,  4; 4,  6,  2];

# D will hold the color data in a form below. e.g.,
D = 20;

# to test CData
hp = patch ('Vertices', P, 'Faces', T, 'CData', D, 'FaceColor', 'interp', 'EdgeColor', 'interp');

#OR to test FaceVertexCData:
# hp = patch ('Vertices', P, 'Faces', T, 'FaceVertexCData', D, 'FaceColor', 'interp', 'EdgeColor', 'interp');

get(hp, 'cdata'),get(hp,'facevertexcdata')




Using Colormap indices:

ONE COLOR:
D = 20
both CData and FaceVertexCData - color all faces the 20th color in the current colormap


ONE COLOR PER FACE:
D = [10 20 30 40]'  # numel(D) = N = number of faces
Both CData and FaceVertexCData:  color Nth face the Nth index # specified in the vector

D = [10 20 30 40]  # numel(D) = N = number of faces
CData:  color Nth face the Nth index # specified in the vector
FaceVertexCData:  error - invalid value for property


ONE COLOR PER VERTEX:
D = [10 20 30 40 50 60]'  # numel(D) = M = number of Vertices
Both CData and FaceVertexCData:  color Nth face the Nth index # specified in the vector

D = [10 20 30 40 50 60]  # numel(D) = M = number of vertices
CData:  color Nth face the Nth index # specified in the vector
FaceVertexCData:  error - invalid value for property


ONE COLOR PER VERTEX, DIFFERENT ON EACH FACE:
D=round(64*rand(size(P,1), size(T,1))) # N x M matrix
CData: specifies one color per vertex per face. if you do facecolor = interp, you'll see that faces sharing vertices can have diff colors on either side of the shared edge.
FaceVertexCData: error. invalid value for array property

D=round(64*rand(size(T,1), size(P,1))) # M x N matrix
CData: specifies one color per vertex per face like above. different color/vertex ordering. Not sure how Octave maps it since the matlab docs say should be NxM.
FaceVertexCData: error. invalid value for array property


Using RGB color specs:

ONE COLOR:
D = [0.1 0.5 0.7]
CData: odd color results. supposedly expects dim 3 vector. facevertexcdata stored as column vector.
FaceVertexCData:  single rgb value applied to all faces (checking CData, it contains the same values changed to a dim3 vector)

D = [0.1 0.5 0.7]'
CData: odd color results. supposedly expects dim 3 vector. facevertexcdata stored as column vector.
FaceVertexCdata: odd color results. Cdata contains a seemingly random 3x4 numeric array.

D = cat(3,0.1 ,0.5, 0.7)
CData: single rgb value applied to all faces. (facevertexdata, same values stored as a row vector)
FaceVertexCData: error. invalid value for array property.


ONE COLOR PER FACE:
D = [0 0.1 0.2; 0.3 0.4 0.5; 0.6 0.7 0.8; 0.9 1.0 0.0] #(Nx3 matrix)
CData: odd color results. Cdata stored as 4x3, FaceVertexCData stored as D(:) (12x1)
FaceVertexCData: One color per face. Cdata stored as 1x4x3 array.

D = D'  #(3xN matrix)
CData: odd color results. Cdata stored as 3x4, FaceVertexCData stored as D(:) (12x1)
FaceVertexCData: Error - invalid value for property.

D = permute([0 0.1 0.2; 0.3 0.4 0.5; 0.6 0.7 0.8; 0.9 1.0 0.0], [1 3 2])  # Nx1x3 array
CData: one color per face.  FaceVertexCData stored as 4x3.
FaceVertexCData:  Error - invalid value for property.


ONE COLOR PER VERTEX:
D = [0 0.1 0.2; 0.3 0.4 0.5; 0.6 0.7 0.8; 0.9 1.0 0.0; 0.1 0.2 0.3; 0.4 0.5 0.6] # M x 3 matrix
CData:  odd color values. Cdata is 6x3. FaceVertexCData is 18x1.
FaceVertexCData: one color per vertex. CData stored as 3x4x3

D = D'  #(3xM matrix)
CData: odd color results. Cdata stored as 3x6, FaceVertexCData stored as D(:) (18x1)
FaceVertexCData: Error - invalid value for property.


D = rand(3x4x3) # dim1&2 size to match x/y/zdata, RGB in dim3
CData: one color per vertex per face. (color can jump across edges). FaceVertexCData stored as 12x3.
FaceVertexCData: Error - invalid value for property.


Nicholas Jankowski <nrjank>
Group Member
Wed 06 Mar 2024 10:40:43 PM UTC, comment #2: 

just adding a note that a handful of behavior checks on cdata and facevertexcdata was done in bug #65421

Nicholas Jankowski <nrjank>
Group Member
Fri 23 Dec 2022 01:52:55 PM UTC, comment #1: 

Confirmed.  The issue isn't in an m-file, but in the C++ code for patch objects which apparently does not have a test for this.

Rik <rik5>
Group administrator
Wed 14 Dec 2022 08:22:49 AM UTC, original submission:  

Octave will run this example, and generate a plot:


np = 30;
p = rand(np, 3);
h = convhull(p);
nfaces = size(h, 1)
val = rand(nfaces + 1, 1);
patch('vertices', p, 'faces', h, 'facevertexcdata', val, 'facecolor', 'flat');
view(3);


where as matlab reports


Warning: Error creating or updating Patch
 Error in value of property  FaceVertexCData
 Number of colors must equal number of vertices or faces


A.R. Burgers <arb>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by arb (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-07 nrjank Summarypatch: case where invalid size of facevertexcdata is not caught patch: input validation for cdata and facevertexcdata needs improvement
    2022-12-23 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f762.
    Corresponding source code