<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<big>Hello All, <br>
<br>
I wonder if I stumbled upon a bug, or if I made a thinking error
myself. <br>
<br>
The issue is: I can get colouring of my Source object only after I
write <br>
it first to a vtk file and then read it back again! <br>
<br>
This is what I do:<br>
<br>
-) I create a single (rectangular) 3D cell from a (handcrafted)
Source type,<br>
subclassed from vtkUnstructuredGridAlgorithm.<br>
This cell has scalar properties assigned to both its vertices
as well as the cell itself.<br>
<br>
-) After "Apply", the box becomes visible (surface
representation)<br>
However, there are no colours. The "Coloring" section in the
<br>
Properties panel does not show the scalar properties. Only<br>
"Solid Color" and "cellNormals" appear as combo-options.<br>
<br>
-) After writing the model to a vtk file, and loading the
latter, the <br>
loaded box does appear in its coloured form, with the scalar
properties <br>
selectable in the "Coloring" combo box. <br>
<br>
Why do the colours not show up immediately after I created
("Apply") the<br>
source object. I naively tried a Modified() on the underlying
unstructed grid object, <br>
but that didn't help.</big><br>
<br>
<big>For completeness, I paste the relevant code as well as the vtk
file (ascii).<br>
<br>
Kind Regards,<br>
Bertwim</big><br>
<br>
<br>
<br>
====================<br>
int sphBoxSourceC::RequestData( vtkInformation *vtkNotUsed(request),<br>
vtkInformationVector
**vtkNotUsed(inputVector),<br>
vtkInformationVector *outputVector)<br>
{<br>
// Get the info object<br>
vtkInformation *outInfo =
outputVector->GetInformationObject(0);<br>
vtkUnstructuredGrid *umesh = vtkUnstructuredGrid::SafeDownCast(
outInfo->Get( vtkDataObject::DATA_OBJECT() ) );<br>
<br>
// Pre-allocate some memory<br>
umesh->Allocate( 1024 );<br>
<br>
// Scalars for the property values<br>
vtkFloatArray* vtxdata = vtkFloatArray::New(); // property
defined on a vertex.<br>
vtkFloatArray* vxldata = vtkFloatArray::New(); // property
defined in a voxel.<br>
<br>
// Specify points.<br>
float r0[] = { 0.0, 0.0, 0.0 };<br>
float r1[] = { 1.0, 0.0, 0.0 };<br>
float r2[] = { 0.0, 1.0, 0.0 };<br>
float r3[] = { 1.0, 1.0, 0.0 };<br>
float r4[] = { 0.0, 0.0, 1.0 };<br>
float r5[] = { 1.0, 0.0, 1.0 };<br>
float r6[] = { 0.0, 1.0, 1.0 };<br>
float r7[] = { 1.0, 1.0, 1.0 };<br>
<br>
// Collect the points in a vtk data structures.<br>
{<br>
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();<br>
points->SetDataType( VTK_FLOAT );<br>
<br>
points->InsertNextPoint( r0 );
vtxdata->InsertNextValue( cos(0.1) );<br>
points->InsertNextPoint( r1 );
vtxdata->InsertNextValue( cos(0.4) );<br>
points->InsertNextPoint( r2 );
vtxdata->InsertNextValue( cos(0.7) );<br>
points->InsertNextPoint( r3 );
vtxdata->InsertNextValue( cos(1.0) );<br>
points->InsertNextPoint( r4 );
vtxdata->InsertNextValue( cos(1.3) );<br>
points->InsertNextPoint( r5 );
vtxdata->InsertNextValue( cos(1.6) );<br>
points->InsertNextPoint( r6 );
vtxdata->InsertNextValue( cos(1.9) );<br>
points->InsertNextPoint( r7 );
vtxdata->InsertNextValue( cos(2.2) );<br>
<br>
// Transfer points to umesh.<br>
umesh->SetPoints( points );<br>
umesh->GetPointData()->SetScalars( vtxdata );<br>
}<br>
<br>
// Cell Topology<br>
vtkIdType vtx[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };<br>
umesh->InsertNextCell( VTK_HEXAHEDRON, 8, vtx );
vxldata->InsertNextValue( 3.14 );<br>
umesh->GetCellData()->SetScalars( vxldata );<br>
<br>
// Write data to a file<br>
{<br>
std::string fileName( "myfile.vtk" );<br>
V3D::Utils::WriteUMesh( umesh, "Rectangular block as umesh",
fileName, VTK_ASCII );<br>
cerr << "Created: " << fileName <<
std::endl;<br>
}<br>
<br>
vtxdata->Delete();<br>
vxldata->Delete();<br>
<br>
return 1;<br>
}<br>
<br>
=======================<br>
The file "myfile.vtk", written above read:<br>
=======================<br>
# vtk DataFile Version
3.0
<br>
Rectangular block as
umesh
<br>
ASCII
<br>
DATASET
UNSTRUCTURED_GRID
<br>
POINTS 8
float
<br>
0 0 0 1 0 0 0 1
0
<br>
1 1 0 0 0 1 1 0
1
<br>
0 1 1 1 1
1
<br>
CELLS 1
9
<br>
8 0 1 3 2 4 5 7
6
<br>
<br>
CELL_TYPES
1
<br>
12
<br>
<br>
CELL_DATA
1
<br>
SCALARS scalars
float
<br>
LOOKUP_TABLE
default
<br>
3.14
<br>
POINT_DATA
8
<br>
SCALARS scalars
float
<br>
LOOKUP_TABLE
default
<br>
0.995004 0.921061 0.764842 0.540302 0.267499 -0.0291995 -0.32329
-0.588501
<br>
=======================<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>