[vtkusers] question ? [Generate the colors for each cell based on color map]

Alex Malyushytskyy alexmalvtk at gmail.com
Fri Aug 24 17:24:54 EDT 2012


I do not want to kill my eyes reading text in red,
so I would only mention that you might need need to let mapper know
what scalar mode to use.
Look at:

virtual void 	SetScalarMode (int)
virtual int 	GetScalarMode ()
void 	SetScalarModeToDefault ()
void 	SetScalarModeToUsePointData ()
void 	SetScalarModeToUseCellData ()
void 	SetScalarModeToUsePointFieldData ()
void 	SetScalarModeToUseCellFieldData ()
void 	SetScalarModeToUseFieldData ()


but want to mention you are choosing a weird way to use look-up table.
Normally you allow Look-up table itself to do the mapping.

Look at: http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/ColorCells
for an example.
What you are trying to do - you manually map the color, then set this
color directly.

Regards,
     Alex






On Fri, Aug 24, 2012 at 5:43 AM, Agata Krasoń <agatakrason at gmail.com> wrote:
> Hi ;)
>
> I have already implemented generation the colors for each point based on
> color map.
> Now I need to generate the colors for each cell(triangle) based on color
> map.
>
>
> For points : I have like this : It works good ;)
>
> vtkSmartPointer<vtkPointData> pd = grid->GetPointData();
>             pd->SetScalars(fd);
>             pd->Update();
>
>             vtkSmartPointer<vtkPolyData> polydata =
> vtkSmartPointer<vtkPolyData>::New();
>             polydata->SetPoints(points);
>             polydata->SetPolys(polys);
>             polydata->GetPointData()->SetScalars(fd);
>
>
>             double bounds[6];
>             polydata->GetBounds(bounds);
>
>             // Find min and max z
>             double minz = bounds[4];
>             double maxz = bounds[5];
>
>             // Create the color map
>             vtkSmartPointer<vtkLookupTable> colorLookupTable =
> vtkSmartPointer<vtkLookupTable>::New();
>             colorLookupTable->SetTableRange(minz, maxz);
>             colorLookupTable->Build();
>
>             // Generate the colors for each point based on the color map
>             vtkSmartPointer<vtkUnsignedCharArray> colors =
> vtkSmartPointer<vtkUnsignedCharArray>::New();
>             colors->SetNumberOfComponents(3);
>             colors->SetName("Colors");
>
>
>
>             for(int i = 0; i < polydata->GetNumberOfPoints(); i++)
>             {
>
>                 double p[3];
>                 polydata->GetPoint(i,p);
>
>                 double dcolor[3];
>                 colorLookupTable->GetColor(p[2], dcolor);
>
>                 unsigned char color[3];
>                 for(unsigned int j = 0; j < 3; j++)
>                 {
>                     color[j] = static_cast<unsigned char>(255.0 *
> dcolor[j]);
>                 }
>
>                 colors->InsertNextTupleValue(color);
>             }
>
>             polydata->GetPointData()->SetScalars(colors);
>             polydata->Update();
>
>             // Save mesh with attributes
>             vtkSmartPointer<vtkPolyDataWriter> pointAttrWriter =
> vtkSmartPointer<vtkPolyDataWriter>::New();
>             pointAttrWriter->SetInput(polydata);
>             pointAttrWriter->SetFileName("meshWithPoints24.08.vtk");
>             pointAttrWriter->Write();
>
>
>
>
>
> But for cells, I have made something like this : It doesn't create a colors
> ?
> There is something wrong with this code ?
>
>             vtkSmartPointer<vtkCellData> pd = grid->GetCellData();
>             pd->SetScalars(fd);
>             pd->Update();
>
>             vtkSmartPointer<vtkPolyData> polydata =
> vtkSmartPointer<vtkPolyData>::New();
>             polydata->SetPoints(points);
>             polydata->SetPolys(polys);
>             polydata->GetCellData()->SetScalars(fd);
>
>
>             double bounds[6];
>             polydata->GetBounds(bounds);
>
>             // Find min and max z
>             double minz = bounds[4];
>             double maxz = bounds[5];
>
>             // Create the color map
>             vtkSmartPointer<vtkLookupTable> colorLookupTable =
> vtkSmartPointer<vtkLookupTable>::New();
>             colorLookupTable->SetTableRange(minz, maxz);
>             colorLookupTable->Build();
>
>             // Generate the colors for each cell based on color map
>             vtkSmartPointer<vtkUnsignedCharArray> attributes =
> vtkSmartPointer<vtkUnsignedCharArray>::New();
>             attributes->SetNumberOfComponents(3);
>             attributes->SetName("Colors");
>
>
>
>             for(int i = 0; i < polydata->GetNumberOfCells(); i++)  // here
> ???
>             {
>
>                 double p[3];
>                 polydata->GetCell(i);    //
>
>                 double dcolor[3];
>                 colorLookupTable->GetColor(p[2], dcolor);
>
>                 unsigned char color[3];
>                 for(unsigned int j = 0; j < 3; j++)
>                 {
>                     color[j] = static_cast<unsigned char>(255.0 *
> dcolor[j]);
>                 }
>
>                 attributes->InsertNextTupleValue(color);
>             }
>
>             polydata->GetCellData()->SetScalars(attributes);
>             polydata->Update();
>
>             // Save mesh with attributes - cells
>             vtkSmartPointer<vtkPolyDataWriter> cellAtrrWriter =
> vtkSmartPointer<vtkPolyDataWriter>::New();
>             cellAtrrWriter->SetInput(polydata);
>             cellAtrrWriter->SetFileName("Celltest.vtk");
>             cellAtrrWriter->Write();
>
>
>
> I would appreciate for any help please ;)
>
> ------------------------------
> agatte
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list