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&lt;vtkPointData&gt; pd = grid-&gt;GetPointData();<br>            pd-&gt;SetScalars(fd);<br>            pd-&gt;Update();<br><br>            vtkSmartPointer&lt;vtkPolyData&gt; polydata = vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
            polydata-&gt;SetPoints(points);<br>            polydata-&gt;SetPolys(polys);<br>            polydata-&gt;GetPointData()-&gt;SetScalars(fd);<br><br><br>            double bounds[6];<br>            polydata-&gt;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&lt;vtkLookupTable&gt; colorLookupTable = vtkSmartPointer&lt;vtkLookupTable&gt;::New();<br>
            colorLookupTable-&gt;SetTableRange(minz, maxz);<br>            colorLookupTable-&gt;Build();<br><br>            // Generate the colors for each point based on the color map<br>            vtkSmartPointer&lt;vtkUnsignedCharArray&gt; colors = vtkSmartPointer&lt;vtkUnsignedCharArray&gt;::New();<br>
            colors-&gt;SetNumberOfComponents(3);<br>            colors-&gt;SetName(&quot;Colors&quot;);<br><br><br><br>            for(int i = 0; i &lt; polydata-&gt;GetNumberOfPoints(); i++)<br>            {<br><br>                double p[3];<br>
                polydata-&gt;GetPoint(i,p);<br><br>                double dcolor[3];<br>                colorLookupTable-&gt;GetColor(p[2], dcolor);<br><br>                unsigned char color[3];<br>                for(unsigned int j = 0; j &lt; 3; j++)<br>
                {<br>                    color[j] = static_cast&lt;unsigned char&gt;(255.0 * dcolor[j]);<br>                }<br><br>                colors-&gt;InsertNextTupleValue(color);<br>            }<br><br>            polydata-&gt;GetPointData()-&gt;SetScalars(colors);<br>
            polydata-&gt;Update();<br><br>            // Save mesh with attributes<br>            vtkSmartPointer&lt;vtkPolyDataWriter&gt; pointAttrWriter = vtkSmartPointer&lt;vtkPolyDataWriter&gt;::New();<br>            pointAttrWriter-&gt;SetInput(polydata);<br>
            pointAttrWriter-&gt;SetFileName(&quot;meshWithPoints24.08.vtk&quot;);<br>            pointAttrWriter-&gt;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&#39;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&lt;vtkCellData&gt; pd = grid-&gt;GetCellData();<br>            pd-&gt;SetScalars(fd);<br>            pd-&gt;Update();<br>
<br>            vtkSmartPointer&lt;vtkPolyData&gt; polydata = vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>            polydata-&gt;SetPoints(points);<br>            polydata-&gt;SetPolys(polys);<br>            polydata-&gt;GetCellData()-&gt;SetScalars(fd);<br>
<br><br>            double bounds[6];<br>            polydata-&gt;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&lt;vtkLookupTable&gt; colorLookupTable = vtkSmartPointer&lt;vtkLookupTable&gt;::New();<br>            colorLookupTable-&gt;SetTableRange(minz, maxz);<br>            colorLookupTable-&gt;Build();<br>
<br>            // Generate the colors for each cell based on color map<br>            vtkSmartPointer&lt;vtkUnsignedCharArray&gt; attributes = vtkSmartPointer&lt;vtkUnsignedCharArray&gt;::New();<br>            attributes-&gt;SetNumberOfComponents(3);<br>
            attributes-&gt;SetName(&quot;Colors&quot;);<br><br><br><br>          <b><span style="color:rgb(255,0,0)">  for(int i = 0; i &lt; polydata-&gt;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-&gt;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-&gt;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 &lt; 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&lt;unsigned char&gt;(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-&gt;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-&gt;GetCellData()-&gt;SetScalars(attributes);</span><br style="color:rgb(255,0,0)">
<span style="color:rgb(255,0,0)">            polydata-&gt;Update();</span><br style="color:rgb(255,0,0)"></b><br>            // Save mesh with attributes - cells<br>            vtkSmartPointer&lt;vtkPolyDataWriter&gt; cellAtrrWriter = vtkSmartPointer&lt;vtkPolyDataWriter&gt;::New();<br>
            cellAtrrWriter-&gt;SetInput(polydata);<br>            cellAtrrWriter-&gt;SetFileName(&quot;Celltest.vtk&quot;);<br>            cellAtrrWriter-&gt;Write();<br><br><br><br>I would appreciate for any help please ;)<br>
<br>------------------------------<br>agatte<br><br> <br>