Hi ;)<br><br>I have already implemented generation the colors for each point based on color map.<br>Now I need to generate the colors for each cell(triangle) based on color map.<br><br><br>For points : I have like this : It works good ;)<br>
<br>vtkSmartPointer<vtkPointData> pd = grid->GetPointData();<br> pd->SetScalars(fd);<br> pd->Update();<br><br> vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();<br>
polydata->SetPoints(points);<br> polydata->SetPolys(polys);<br> polydata->GetPointData()->SetScalars(fd);<br><br><br> double bounds[6];<br> polydata->GetBounds(bounds);<br>
<br> // Find min and max z<br> double minz = bounds[4];<br> double maxz = bounds[5];<br><br> // Create the color map<br> vtkSmartPointer<vtkLookupTable> colorLookupTable = vtkSmartPointer<vtkLookupTable>::New();<br>
colorLookupTable->SetTableRange(minz, maxz);<br> colorLookupTable->Build();<br><br> // Generate the colors for each point based on the color map<br> vtkSmartPointer<vtkUnsignedCharArray> colors = vtkSmartPointer<vtkUnsignedCharArray>::New();<br>
colors->SetNumberOfComponents(3);<br> colors->SetName("Colors");<br><br><br><br> for(int i = 0; i < polydata->GetNumberOfPoints(); i++)<br> {<br><br> double p[3];<br>
polydata->GetPoint(i,p);<br><br> double dcolor[3];<br> colorLookupTable->GetColor(p[2], dcolor);<br><br> unsigned char color[3];<br> for(unsigned int j = 0; j < 3; j++)<br>
{<br> color[j] = static_cast<unsigned char>(255.0 * dcolor[j]);<br> }<br><br> colors->InsertNextTupleValue(color);<br> }<br><br> polydata->GetPointData()->SetScalars(colors);<br>
polydata->Update();<br><br> // Save mesh with attributes<br> vtkSmartPointer<vtkPolyDataWriter> pointAttrWriter = vtkSmartPointer<vtkPolyDataWriter>::New();<br> pointAttrWriter->SetInput(polydata);<br>
pointAttrWriter->SetFileName("meshWithPoints24.08.vtk");<br> pointAttrWriter->Write();<br><br><br><br><br><b style="color:rgb(255,0,0)"><br>But for cells, I have made something like this : It doesn't create a colors ?</b><br>
<b><span style="color:rgb(255,0,0)">There is something wrong with this code ? </span></b><br><br> vtkSmartPointer<vtkCellData> pd = grid->GetCellData();<br> pd->SetScalars(fd);<br> pd->Update();<br>
<br> vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();<br> polydata->SetPoints(points);<br> polydata->SetPolys(polys);<br> polydata->GetCellData()->SetScalars(fd);<br>
<br><br> double bounds[6];<br> polydata->GetBounds(bounds);<br><br> // Find min and max z<br> double minz = bounds[4];<br> double maxz = bounds[5];<br><br> // Create the color map<br>
vtkSmartPointer<vtkLookupTable> colorLookupTable = vtkSmartPointer<vtkLookupTable>::New();<br> colorLookupTable->SetTableRange(minz, maxz);<br> colorLookupTable->Build();<br>
<br> // Generate the colors for each cell based on color map<br> vtkSmartPointer<vtkUnsignedCharArray> attributes = vtkSmartPointer<vtkUnsignedCharArray>::New();<br> attributes->SetNumberOfComponents(3);<br>
attributes->SetName("Colors");<br><br><br><br> <b><span style="color:rgb(255,0,0)"> for(int i = 0; i < polydata->GetNumberOfCells(); i++) // here ??? </span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)"> {</span><br style="color:rgb(255,0,0)"><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> double p[3];</span><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> polydata->GetCell(i); //</span><br style="color:rgb(255,0,0)">
<br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> double dcolor[3];</span><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> colorLookupTable->GetColor(p[2], dcolor);</span><br style="color:rgb(255,0,0)">
<br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> unsigned char color[3];</span><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> for(unsigned int j = 0; j < 3; j++)</span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)"> {</span><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> color[j] = static_cast<unsigned char>(255.0 * dcolor[j]);</span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)"> }</span><br style="color:rgb(255,0,0)"><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> attributes->InsertNextTupleValue(color);</span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)"> }</span><br style="color:rgb(255,0,0)"><br style="color:rgb(255,0,0)"><span style="color:rgb(255,0,0)"> polydata->GetCellData()->SetScalars(attributes);</span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)"> polydata->Update();</span><br style="color:rgb(255,0,0)"></b><br> // Save mesh with attributes - cells<br> vtkSmartPointer<vtkPolyDataWriter> cellAtrrWriter = vtkSmartPointer<vtkPolyDataWriter>::New();<br>
cellAtrrWriter->SetInput(polydata);<br> cellAtrrWriter->SetFileName("Celltest.vtk");<br> cellAtrrWriter->Write();<br><br><br><br>I would appreciate for any help please ;)<br>
<br>------------------------------<br>agatte<br><br> <br>