<html><head></head><body bgcolor='#FFFFFF' style='font-size:12px;background-color:#FFFFFF;font-family:Verdana, Arial, sans-serif;'>Hey,<br/><br/>I am new to this list and looking for the answer to my current problem.<br/>Unfortunately, I could not find a corresponding topic in the wiki.<br/><br/>What I want to do, is drawing multiple cubes (several thousands) with different colors.<br/><br/>First, I tried to solve the problem by using the vtkCubeSource class.<br/>Here is the C++ function:<br/><br/>void mapViewer::drawCubesViaCubeSource(gridMap map)<br/>{<br/>&nbsp;&nbsp;&nbsp; // Create renderer and render window<br/>&nbsp;&nbsp;&nbsp; vtkRenderer *m_ren = vtkRenderer::New();<br/>&nbsp;&nbsp; &nbsp;vtkRenderWindow *renWin = vtkRenderWindow::New();<br/>&nbsp;&nbsp; &nbsp;renWin-&gt;AddRenderer(m_ren);<br/><br/>&nbsp;&nbsp; &nbsp;// Create interactor<br/>&nbsp;&nbsp; &nbsp;vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br/>&nbsp;&nbsp; &nbsp;iren-&gt;SetRenderWindow(renWin);<br/><br/>&nbsp;&nbsp; &nbsp;// Step through all map cells<br/>&nbsp;&nbsp; &nbsp;for (ushort n=0;n&lt;map.GetMapInfo().cellsNorth; n++)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for (ushort e=0;e&lt;map.GetMapInfo().cellsEast; e++)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vector&lt;mapData&gt; mapElement = map.getElement(n,e);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (uint i=0; i&lt;mapElement.size(); i++)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (mapElement[i].isValid())<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; drawCube(n, e, (-mapElement[i].height/map.GetMapInfo().cubeHeight), map.GetMapInfo().cellSize, map.GetMapInfo().cubeHeight, mapElement[i].color[0], mapElement[i].color[1], mapElement[i].color[2]);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mapElement.clear();<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp; // Set window background color<br/>&nbsp;&nbsp; &nbsp;m_ren-&gt;SetBackground(0,0,0);<br/><br/>&nbsp;&nbsp; &nbsp;// Render an image (lights and cameras are created automatically)<br/>&nbsp;&nbsp; &nbsp;renWin-&gt;Render();<br/><br/>&nbsp;&nbsp; &nbsp;// Begin mouse interaction<br/>&nbsp;&nbsp; &nbsp;iren-&gt;Start();<br/>}<br/><br/><span style="font-family:verdana,geneva,sans-serif;">This is the corresponding function &quot;drawCube&quot; which is called</span><br/><br/>void mapViewer::drawCube(double n, double e, double d, float cellSize, float cubeHeight, unsigned char r, unsigned char g, unsigned char b)<br/>{<br/>&nbsp;&nbsp; &nbsp;// Create a cube<br/>&nbsp;&nbsp; &nbsp;vtkCubeSource* cube = vtkCubeSource::New();<br/>&nbsp;&nbsp; &nbsp;cube-&gt;SetCenter(e*cellSize,-d*cubeHeight,-n*cellSize);<br/>&nbsp;&nbsp; &nbsp;cube-&gt;SetXLength(cellSize);<br/>&nbsp;&nbsp; &nbsp;cube-&gt;SetYLength(cubeHeight);<br/>&nbsp;&nbsp; &nbsp;cube-&gt;SetZLength(cellSize);<br/>&nbsp;<br/>&nbsp;&nbsp; &nbsp;// Create a mapper and actor<br/>&nbsp;&nbsp; &nbsp;vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();<br/>&nbsp;&nbsp; &nbsp;mapper-&gt;SetInputConnection(cube-&gt;GetOutputPort());<br/>&nbsp;&nbsp; &nbsp;<br/>&nbsp;&nbsp; &nbsp;vtkActor* cubeActor = vtkActor::New();<br/>&nbsp;&nbsp; &nbsp;cubeActor-&gt;GetProperty()-&gt;SetColor(floor(float(r))/255,floor(float(g))/255,floor(float(b))/255);<br/>&nbsp;&nbsp; &nbsp;cubeActor-&gt;SetMapper(mapper);<br/>&nbsp;&nbsp; &nbsp;<br/>&nbsp;&nbsp; &nbsp;m_ren-&gt;AddActor(cubeActor);<br/><br/>&nbsp;&nbsp; &nbsp;// Clean-up<br/>&nbsp;&nbsp;&nbsp; cubeActor-&gt;Delete();<br/>&nbsp;&nbsp;&nbsp; cube-&gt;Delete();<br/>&nbsp;&nbsp;&nbsp; mapper-&gt;Delete();<br/>}<br/><br/>The problem was that after rendering a lot of cubes, the mouse interaction did not work very well. When you try to move the displayed data in the vtk window, everything is very slow.<br/>This may be the case because the visualization blocks a lot of system memory (about 700MB).<br/>In the next approach, I tried to use the vtkHexahedron class to fulfill the task.<br/>You can see the function here:<br/><br/>void mapViewer::drawCubesViaHexahedron(gridMap map)<br/>{<br/>&nbsp;&nbsp;&nbsp; // Create renderer and render window<br/>&nbsp;&nbsp; &nbsp;m_ren = vtkRenderer::New();<br/>&nbsp;&nbsp; &nbsp;vtkRenderWindow *renWin = vtkRenderWindow::New();<br/>&nbsp;&nbsp; &nbsp;renWin-&gt;AddRenderer(m_ren);<br/><br/>&nbsp;&nbsp; &nbsp;// Create interactor<br/>&nbsp;&nbsp; &nbsp;vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br/>&nbsp;&nbsp; &nbsp;iren-&gt;SetRenderWindow(renWin);<br/><br/>&nbsp;&nbsp; &nbsp;// Create the point structure<br/>&nbsp;&nbsp; &nbsp;vtkSmartPointer&lt;vtkPoints&gt; points = vtkSmartPointer&lt;vtkPoints&gt;::New();<br/><br/>&nbsp;&nbsp; &nbsp;// Step through all map cells<br/>&nbsp;&nbsp; &nbsp;for (ushort n=0;n&lt;map.GetMapInfo().cellsNorth; n++)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for (ushort e=0;e&lt;map.GetMapInfo().cellsEast; e++)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vector&lt;mapData&gt; mapElement = map.getElement(n,e);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (uint i=0; i&lt;mapElement.size(); i++)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (mapElement[i].isValid())<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br/><br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Setup the coordinates of eight points<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // (the two faces must be in counter clockwise order as viewd from the outside)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P0[3] = {float(e)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2, mapElement[i].height-map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P1[3] = {float(e)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2, mapElement[i].height-map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P2[3] = {float(e)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2, mapElement[i].height+map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P3[3] = {float(e)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2, mapElement[i].height+map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P4[3] = {float(e)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2, mapElement[i].height-map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P5[3] = {float(e)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2, mapElement[i].height-map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P6[3] = {float(e)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2, mapElement[i].height+map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double P7[3] = {float(e)*map.GetMapInfo().cellSize-map.GetMapInfo().cellSize/2, mapElement[i].height+map.GetMapInfo().cubeHeight/2, -(float(n)*map.GetMapInfo().cellSize+map.GetMapInfo().cellSize/2)};<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create the points<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P0);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P1);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P2);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P3);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P4);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P5);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P6);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; points-&gt;InsertNextPoint(P7);<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mapElement.clear();<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;}<br/>&nbsp;<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp; &nbsp;//create the hexahedron<br/>&nbsp;&nbsp; &nbsp;vtkHexahedron * *theHex;<br/>&nbsp;&nbsp; &nbsp;theHex = new vtkHexahedron*[map.getNumberOfFilledCells()];<br/><br/>&nbsp;&nbsp; &nbsp;for(int i=0;i&lt;map.getNumberOfFilledCells();i++)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; theHex[i] = vtkHexahedron::New();<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; theHex[i]-&gt;GetPointIds()-&gt;SetNumberOfIds(8);&nbsp;<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; for (int j = 0; j &lt;8; j++)<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; theHex[i]-&gt;GetPointIds()-&gt;SetId(j,j+(i*8));&nbsp; //this maps internal id 0-7 to global point Id<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp; &nbsp;}<br/><br/>&nbsp;&nbsp; &nbsp;//create an unstructured grid for the hexahedron<br/>&nbsp;&nbsp; &nbsp;vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();<br/>&nbsp;&nbsp; &nbsp;theGrid-&gt;Allocate(map.getNumberOfFilledCells());<br/>&nbsp;&nbsp; &nbsp;for(int i =0;i&lt;map.getNumberOfFilledCells();i++)<br/>&nbsp;&nbsp; &nbsp;{<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; theGrid-&gt;InsertNextCell(theHex[i]-&gt;GetCellType(),<br/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; theHex[i]-&gt;GetPointIds());<br/>&nbsp;&nbsp; &nbsp;}<br/>&nbsp;&nbsp; &nbsp;theGrid-&gt;SetPoints(points);<br/><br/>&nbsp;&nbsp; &nbsp;//create a mapper for the hexahedron<br/>&nbsp;&nbsp; &nbsp;vtkDataSetMapper *theHexMapper;<br/>&nbsp;&nbsp; &nbsp;theHexMapper = vtkDataSetMapper::New();<br/>&nbsp;&nbsp; &nbsp;theHexMapper-&gt;SetInput(theGrid);<br/><br/>&nbsp;&nbsp; &nbsp;//create an actor<br/>&nbsp;&nbsp; &nbsp;vtkSmartPointer&lt;vtkActor&gt; actor = vtkSmartPointer&lt;vtkActor&gt;::New();<br/>&nbsp;&nbsp; &nbsp;actor-&gt;SetMapper(theHexMapper);<br/>&nbsp;&nbsp; &nbsp;<br/>&nbsp;&nbsp; &nbsp;m_ren-&gt;AddActor(actor);<br/><br/>&nbsp;&nbsp;&nbsp; // Set window background color<br/>&nbsp;&nbsp; &nbsp;m_ren-&gt;SetBackground(0,0,0);<br/><br/>&nbsp;&nbsp; &nbsp;// Render an image (lights and cameras are created automatically)<br/>&nbsp;&nbsp; &nbsp;renWin-&gt;Render();<br/><br/>&nbsp;&nbsp; &nbsp;// Begin mouse interaction<br/>&nbsp;&nbsp; &nbsp;iren-&gt;Start();<br/>}<br/><br/>Using the second approach led to very good results.<br/>Furthermore it reduced the blocked system memory to about 100MB.<br/>My problem is now:<br/>By now, there are no colors in the second approach.<br/>How can I color the cubes. It is important to know that every cube has to get a different color.<br/>I have no clue how to solve this problem.<br/><br/>Any ideas?<br/><br/>I would appreciate any help.<br/>Thanks in advance.<br/><br/>Greetings,<br/>stone<br/><br/><br/>&nbsp;&nbsp;<br><br><table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#000000"><img src="https://img.ui-portal.de/p.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td style="font-family:verdana; font-size:12px; line-height:17px;">Schon geh&ouml;rt? WEB.DE hat einen genialen Phishing-Filter in die&nbsp;&nbsp;&nbsp;<br>Toolbar eingebaut! <a href="http://produkte.web.de/go/toolbar"><b>http://produkte.web.de/go/toolbar</b></a></td></tr></table>
</body></html>