Commit 5081b717 authored by David Partyka's avatar David Partyka
Browse files

BUG: Fixes for VRMLImporter and a new test.

1) Currently the class does not support the "normalIndex" field.  It assumed that the number of normals matched the number or vertex.  The "normalIndex" field was ignored.  The code has been changed to process the normals the same as the "tcoords" in that it correctly maps the normals to the vertex points.

2) The "colorIndex" field always assumed that the colors are ColorsPerVertex.  Actually it can be specified by colors per vertex or colors per face.  The code was changed that if the number of color index values match the number of faces it maps the colors by face and not be vertex.

3) The "rotation" command in the "Transform" keyword is not supported.  This was not added but should be noted as a bug.
parent 731063e0
......@@ -13,6 +13,7 @@ IF (VTK_DATA_ROOT)
TestLegendScaleActor.cxx
TestPieChartActor.cxx
TestSpiderPlotActor.cxx
TestVRMLNormals.cxx
)
# Temporarily disable LIC tests on non-windows platforms
IF (VTK_USE_GLSL_SHADERS AND WIN32)
......
......@@ -5400,6 +5400,7 @@ vtkVRMLImporter::vtkVRMLImporter ()
this->CurrentPoints = NULL;
this->CurrentScalars = NULL;
this->CurrentNormals = NULL;
this->CurrentNormalCells = NULL;
this->CurrentTCoords = NULL;
this->CurrentTCoordCells = NULL;
this->CurrentMapper = NULL;
......@@ -5553,6 +5554,10 @@ vtkVRMLImporter::~vtkVRMLImporter()
{
this->CurrentTCoordCells->Delete();
}
if (this->CurrentNormalCells)
{
this->CurrentNormalCells->Delete();
}
if (this->CurrentScalars)
{
this->CurrentScalars->Delete();
......@@ -5826,49 +5831,89 @@ vtkVRMLImporter::exitNode()
// a similar scheme is implemented in vtkOBJReader
int tcoords_correspond; // (boolean)
if (this->CurrentTCoords==NULL || this->CurrentTCoordCells==NULL)
if ( (this->CurrentTCoords==NULL || this->CurrentTCoordCells==NULL) && (this->CurrentNormals==NULL || this->CurrentNormalCells==NULL) )
tcoords_correspond=1; // there aren't any, can proceed
else if (this->CurrentTCoords->GetNumberOfTuples()!=this->CurrentPoints->GetNumberOfPoints())
else if (this->CurrentTCoords && this->CurrentTCoords->GetNumberOfTuples()!=this->CurrentPoints->GetNumberOfPoints())
tcoords_correspond=0; // false, must rejig
else if (this->CurrentNormals && this->CurrentNormals->GetNumberOfTuples()!=this->CurrentPoints->GetNumberOfPoints())
tcoords_correspond=0; // false, must rejig
else
{
// the number of polygon faces and texture faces must be equal.
// if they are not then something is wrong
if (this->CurrentTCoordCells->GetNumberOfCells() !=
if (this->CurrentTCoordCells && this->CurrentTCoordCells->GetNumberOfCells() !=
this->CurrentMapper->GetInput()->GetPolys()->GetNumberOfCells())
{
vtkErrorMacro(<<"Number of faces does not match texture faces, output may not be correct")
tcoords_correspond=1; // don't rejig
}
else if (this->CurrentNormalCells && this->CurrentNormalCells->GetNumberOfCells() !=
this->CurrentMapper->GetInput()->GetPolys()->GetNumberOfCells())
{
vtkErrorMacro(<<"Number of faces does not match normal faces, output may not be correct")
tcoords_correspond=1; // don't rejig
}
else
{
// count of tcoords and points is the same, must run through indices to see if they
// correspond by index point-for-point
tcoords_correspond=1; // assume true until found otherwise
vtkIdType DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_pts=-1,*pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_tcoord_pts=-1,*tcoord_pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
this->CurrentMapper->GetInput()->GetPolys()->InitTraversal();
this->CurrentTCoordCells->InitTraversal();
int i,j;
for (i=0;i<this->CurrentTCoordCells->GetNumberOfCells();i++)
if (this->CurrentTCoords && this->CurrentTCoordCells)
{
this->CurrentMapper->GetInput()->GetPolys()->GetNextCell(n_pts,pts);
this->CurrentTCoordCells->GetNextCell(n_tcoord_pts,tcoord_pts);
if (n_pts!=n_tcoord_pts)
vtkIdType DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_pts=-1,*pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_tcoord_pts=-1,*tcoord_pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
this->CurrentMapper->GetInput()->GetPolys()->InitTraversal();
this->CurrentTCoordCells->InitTraversal();
int i,j;
for (i=0;i<this->CurrentTCoordCells->GetNumberOfCells();i++)
{
vtkErrorMacro(<<"Face size differs to texture face size, output may not be correct")
break;
this->CurrentMapper->GetInput()->GetPolys()->GetNextCell(n_pts,pts);
this->CurrentTCoordCells->GetNextCell(n_tcoord_pts,tcoord_pts);
if (n_pts!=n_tcoord_pts)
{
vtkErrorMacro(<<"Face size differs to texture face size, output may not be correct")
break;
}
for (j=0;j<n_pts;j++)
{
if (pts[j]!=tcoord_pts[j])
{
tcoords_correspond=0; // have found an exception
break;
}
}
}
for (j=0;j<n_pts;j++)
}
if (this->CurrentNormals && this->CurrentNormalCells)
{
vtkIdType DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_pts=-1,*pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_normal_pts=-1,*normal_pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
this->CurrentMapper->GetInput()->GetPolys()->InitTraversal();
this->CurrentNormalCells->InitTraversal();
int i,j;
for (i=0;i<this->CurrentNormalCells->GetNumberOfCells();i++)
{
if (pts[j]!=tcoord_pts[j])
this->CurrentMapper->GetInput()->GetPolys()->GetNextCell(n_pts,pts);
this->CurrentNormalCells->GetNextCell(n_normal_pts,normal_pts);
if (n_pts!=n_normal_pts)
{
tcoords_correspond=0; // have found an exception
vtkErrorMacro(<<"Face size differs to normal face size, output may not be correct")
break;
}
for (j=0;j<n_pts;j++)
{
if (pts[j]!=normal_pts[j])
{
tcoords_correspond=0; // have found an exception
break;
}
}
}
}
}
}
......@@ -5910,23 +5955,35 @@ vtkVRMLImporter::exitNode()
// also copy its normals into new_normals
// also copy its scalar into new_scalars
this->CurrentMapper->GetInput()->GetPolys()->InitTraversal();
this->CurrentTCoordCells->InitTraversal();
if (this->CurrentTCoordCells)
this->CurrentTCoordCells->InitTraversal();
if (this->CurrentNormalCells)
this->CurrentNormalCells->InitTraversal();
int i,j;
vtkIdType DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_pts=-1,*pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_tcoord_pts=-1,*tcoord_pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
vtkIdType n_normal_pts=-1,*normal_pts = &DUMMY_WARNING_PREVENTION_MECHANISM;
for (i=0;i<this->CurrentMapper->GetInput()->GetPolys()->GetNumberOfCells();i++)
{
this->CurrentMapper->GetInput()->GetPolys()->GetNextCell(n_pts,pts);
this->CurrentTCoordCells->GetNextCell(n_tcoord_pts,tcoord_pts);
if (this->CurrentTCoordCells)
this->CurrentTCoordCells->GetNextCell(n_tcoord_pts,tcoord_pts);
if (this->CurrentNormalCells)
this->CurrentNormalCells->GetNextCell(n_normal_pts,normal_pts);
// If some vertices have tcoords and not others
// then we must do something else VTK will complain. (crash on render attempt)
// Easiest solution is to delete polys that don't have complete tcoords (if there
// are any tcoords in the dataset)
if (n_pts!=n_tcoord_pts && this->CurrentTCoords->GetNumberOfTuples()>0)
if (this->CurrentTCoords && n_pts!=n_tcoord_pts && this->CurrentTCoords->GetNumberOfTuples()>0)
{
// skip this poly
vtkDebugMacro(<<"Skipping poly "<<i+1<<" (1-based index)");
}
else if (this->CurrentNormals && n_pts!=n_normal_pts && this->CurrentNormals->GetNumberOfTuples()>0)
{
// skip this poly
vtkDebugMacro(<<"Skipping poly "<<i+1<<" (1-based index)");
......@@ -5940,8 +5997,8 @@ vtkVRMLImporter::exitNode()
if (this->CurrentTCoords && n_tcoord_pts>0)
new_tcoords->InsertNextTuple(this->CurrentTCoords->GetTuple(tcoord_pts[j]));
// copy the normal for this point across (if any)
if (this->CurrentNormals)
new_normals->InsertNextTuple(this->CurrentNormals->GetTuple(pts[j]));
if (this->CurrentNormals && n_normal_pts>0)
new_normals->InsertNextTuple(this->CurrentNormals->GetTuple(normal_pts[j]));
// copy the scalar for this point across
if (this->CurrentScalars)
new_scalars->InsertNextTuple(this->CurrentScalars->GetTuple(pts[j]));
......@@ -6324,21 +6381,43 @@ vtkVRMLImporter::exitField()
cells = pd->GetLines();
cells->InitTraversal();
index = 0;j = 0;
cells->GetNextCell(npts, pts);
for (int i=0;i <= yylval.mfint32->GetMaxId();i++)
// At this point we either have colors index by vertex or faces
// If faces, num of color indexes must match num of faces else
// we assume index by vertex.
if ((yylval.mfint32->GetMaxId() + 1) == pd->GetNumberOfPolys())
{
if (yylval.mfint32->GetValue(index) == -1)
for (int i=0;i <= yylval.mfint32->GetMaxId();i++)
{
cells->GetNextCell(npts, pts);
// Pass by the -1
index++;
j = 0;
if (yylval.mfint32->GetValue(i) >= 0)
{
cells->GetNextCell(npts, pts);
for (j = 0; j < npts; j++)
{
this->CurrentScalars->SetComponent(pts[j], 0, yylval.mfint32->GetValue(i));
}
}
}
else
}
// else handle colorindex by vertex
else
{
cells->GetNextCell(npts, pts);
for (int i=0;i <= yylval.mfint32->GetMaxId();i++)
{
// Redirect color into scalar position
this->CurrentScalars->SetComponent(pts[j++], 0,
if (yylval.mfint32->GetValue(index) == -1)
{
cells->GetNextCell(npts, pts);
// Pass by the -1
index++;
j = 0;
}
else
{
// Redirect color into scalar position
this->CurrentScalars->SetComponent(pts[j++], 0,
yylval.mfint32->GetValue(index++));
}
}
}
}
......@@ -6433,6 +6512,32 @@ vtkVRMLImporter::exitField()
}
yylval.mfint32->Reset();this->DeleteObject(yylval.mfint32);
}
else if (strcmp(fr->fieldName, "normalIndex") == 0)
{
if (this->CurrentNormalCells) {
this->CurrentNormalCells->Delete();
}
this->CurrentNormalCells = vtkCellArray::New();
// read the indices of the normals and assign accordingly
int index, i, cnt;
index = i = cnt = 0;
for (i = 0;i <= yylval.mfint32->GetMaxId();i++)
{
if (yylval.mfint32->GetValue(i) == -1)
{
this->CurrentNormalCells->InsertNextCell(cnt,
(vtkIdType*)yylval.mfint32->GetPointer(index));
index = i+1;
cnt = 0;
}
else
{
cnt++;
}
}
yylval.mfint32->Reset();this->DeleteObject(yylval.mfint32);
}
else
{
}
......
......@@ -38,11 +38,14 @@
// in). This, in a way, removes the need for the route and script mechanism
// (not completely though).
//
// .SECTION Thanks
// Thanks to Russ Coucher of Areva for numerous bug fixes and a new test.
//
// .SECTION See Also
// vtkImporter
/* ======================================================================
Importer based on BNF Yacc and Lex parser definition from:
**************************************************
......@@ -143,6 +146,7 @@ private:
vtkAlgorithm *CurrentSource;
vtkPoints *CurrentPoints;
vtkFloatArray *CurrentNormals;
vtkCellArray *CurrentNormalCells;
vtkFloatArray *CurrentTCoords;
vtkCellArray *CurrentTCoordCells;
vtkLookupTable *CurrentLut;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment