[vtkusers] Pop quiz: what does this code do?
Simon Ouellette
s.ouellette1 at gmail.com
Fri Nov 6 15:54:46 EST 2009
Hi,
I've been trying for a couple of days to draw an Unstructured Grid of
vtkTetra points that I was previously drawing using volume render, but now
want to draw using "normal" rendering because I want to be able to use the
VRML exporation functionality. I've tried a lot of things, but the simplest
thing (that I don't understand why it doesn't work) is the following code,
which draws absolutely nothing. I'm confident that the rendering code is
correct, because if I replace the visualization pipeline code with the
"combxyz.bin", "combq.bin" vtkPLOT3DReader to vtkContourFilter example (i
forgot the filename), I see the graph appear. Clearly what I'm doing doesn't
work, but it would help me learn VTK if someone would explain what my code
ACTUALLY does in the background (and hence why it fails):
=== start of code ===
// Create the UNstructured grid for the 3D model
vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
vtkPoints *tetraPoints = vtkPoints::New();
vtkDoubleArray *scalars = vtkDoubleArray::New();
// generate 3D model
for (int p = 0; p < m_fusion->GetNumPoints(); p++)
{
vtkTetra *aTetra = vtkTetra::New();
CEvidencePoint *pt = m_fusion->GetPoint(p);
if (pt == NULL)
continue;
if (pt->evidence_for < 0.0)
pt->evidence_for = 0.0;
if (pt->evidence_for > 1.0)
pt->evidence_for = 1.0;
tetraPoints->InsertPoint((p * 4) + 0, (double)((pt->x *
DEFAULT_X_WIDTH) / x_dim) + 0.0,
((pt->y * DEFAULT_X_WIDTH) / x_dim) + 0.0,
((pt->z * DEFAULT_X_WIDTH) / x_dim) + 0.0);
scalars->InsertValue((p * 4) + 0, pt->evidence_for * 100);
tetraPoints->InsertPoint((p * 4) + 1, (double)((pt->x *
DEFAULT_X_WIDTH) / x_dim) + 1.0,
((pt->y * DEFAULT_X_WIDTH) / x_dim) + 0.0,
((pt->z * DEFAULT_X_WIDTH) / x_dim) + 0.0);
scalars->InsertValue((p * 4) + 1, pt->evidence_for * 100);
tetraPoints->InsertPoint((p * 4) + 2, (double)((pt->x *
DEFAULT_X_WIDTH) / x_dim) + 0.5,
((pt->y * DEFAULT_X_WIDTH) / x_dim) + 1.0,
((pt->z * DEFAULT_X_WIDTH) / x_dim) + 0.0);
scalars->InsertValue((p * 4) + 2, pt->evidence_for * 100);
tetraPoints->InsertPoint((p * 4) + 3, (double)((pt->x *
DEFAULT_X_WIDTH) / x_dim) + 0.5,
((pt->y * DEFAULT_X_WIDTH) / x_dim) + 0.5,
((pt->z * DEFAULT_X_WIDTH) / x_dim) + 1.0);
scalars->InsertValue((p * 4) + 3, pt->evidence_for * 100);
for (int i = 0; i < 4; i++)
(aTetra->GetPointIds())->InsertId(i, (p * 4) + i);
// add voxel to the list
ugrid->InsertNextCell(aTetra->GetCellType(), aTetra->GetPointIds());
ugrid->SetPoints(tetraPoints);
(ugrid->GetPointData())->SetScalars(scalars);
aTetra->Delete();
}
// transform to poly data
vtkUnstructuredGridGeometryFilter *ugrid_to_poly =
vtkUnstructuredGridGeometryFilter::New();
ugrid_to_poly->SetInput(ugrid);
ugrid_to_poly->Update();
vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
normals->SetInputConnection(ugrid_to_poly->GetOutputPort());
normals->SetFeatureAngle(45.0);
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->ScalarVisibilityOn();
mapper->SetInputConnection(normals->GetOutputPort());
mapper->SetScalarRange(0.0, 1500.0);
mapper->SetScalarModeToUsePointData();
mapper->ColorByArrayComponent("Velocity Magnitude", 0.0);
vtkActor *graph = vtkActor::New();
graph->SetMapper(mapper);
graph->SetNumberOfCloudPoints(1000.0);
this->Props->AddItem(graph);
== end of code ==
I can also confirm that there ARE points of data (m_fusion->GetNumPoints() >
0) because the exact same code was correctly generating my unstructured grid
when it was rendered using volume rendering.
I also tried without the vtkPolyDataNormals (not sure why it's even there
anyway), and I get some assert on a ComputeBounds() somewhere in the
rendering code.
Thanks,
Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091106/bdf1414d/attachment.htm>
More information about the vtkusers
mailing list