[vtkusers] Memo: True RGB values to vtkTubeFilter - How?

Divya Rathore divyaksr at iitk.ac.in
Tue Feb 20 07:58:51 EST 2007


Would be real nice if someone could reply.. :)


How to send TRUE 24 Bit RGB values (in the range 0 to 255 for each R,G,B
plane) to vtkTubeFilter for each X,Y,Z coordinate?
I can't seem to get the true color representation. Is the default some 256
color or something?
I am attaching the code I am using.. would be really nice if someone could
point out what is going wrong.

Essentially I have a set of coordinates alongwith their RGB values and I
want a Tube out of them..


warm regards,
- Divya Rathore




vtkPoints* temp_pts = vtkPoints::New(); // XYZ coords
vtkPoints* scalar_rgb = vtkPoints::New(); // RGB values

// Populate pts and RGB values
for(int k=0; k < num_3D_points; k++)
{
    temp_pts->InsertPoint(k,
         (double) Data[count1++],
         (double) Data[count1++],
         (double) Data[count1++]
         );
    scalar_rgb->InsertPoint(k,
         (double) DataRGBval[count2++],
         (double) DataRGBval[count2++],
         (double) DataRGBval[count2++]
         ); // NOTE*** values in DataRGBval[] are in range [0,255] NOT [0,1]
}


// Create the polyline.
vtkCellArray *lines = vtkCellArray::New();
int numPoints = temp_pts->GetNumberOfPoints();
lines->InsertNextCell(numPoints);
for (int j = 0; j < numPoints; j++) lines->InsertCellPoint(j);


// Insert Scalars.
vtkFloatArray *scalars = vtkFloatArray::New();
scalars->SetNumberOfComponents(3);
double pts[3];
for(int j=0; j < numPoints; j++)
{
    scalar_rgb->GetPoint(j,pts);
    scalars->InsertTuple3(j, (float)pts[0]/255.0, (float)pts[1]/255.0,
(float)pts[2]/255.0);
} // division by 255.0 so that data is in range [0,1]


vtkPolyData *profileData = vtkPolyData::New();
profileData->SetPoints((vtkPoints *)(temp_pts));
profileData->SetLines(lines);
profileData->GetPointData()->SetScalars(scalars);
profileData->BuildLinks();


// Add thickness to the resulting line.
vtkTubeFilter *axesTubes = vtkTubeFilter::New();
axesTubes->SetNumberOfSides(12);
axesTubes->SetInput(profileData);
axesTubes->SetRadius(0.3);


vtkPolyDataMapper *axesMapper = vtkPolyDataMapper::New();
axesMapper->SetColorModeToMapScalars(); // This is important i guess
axesMapper->SetScalarRange(0,numPoints-1);
axesMapper->SetInput(axesTubes->GetOutput());

vtkActor *axesActor = vtkActor::New();
axesActor->SetMapper(axesMapper);

ren1->AddActor(axesActor); // add to renderer
_______________________________________________
This is the private VTK discussion list.
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070220/0ae884f9/attachment.htm>


More information about the vtkusers mailing list