<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/> // Create renderer and render window<br/> vtkRenderer *m_ren = vtkRenderer::New();<br/> vtkRenderWindow *renWin = vtkRenderWindow::New();<br/> renWin->AddRenderer(m_ren);<br/><br/> // Create interactor<br/> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br/> iren->SetRenderWindow(renWin);<br/><br/> // Step through all map cells<br/> for (ushort n=0;n<map.GetMapInfo().cellsNorth; n++)<br/> {<br/> for (ushort e=0;e<map.GetMapInfo().cellsEast; e++)<br/> {<br/> vector<mapData> mapElement = map.getElement(n,e);<br/> for (uint i=0; i<mapElement.size(); i++)<br/> {<br/> if (mapElement[i].isValid())<br/> 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/> }<br/> mapElement.clear();<br/> }<br/> }<br/><br/> // Set window background color<br/> m_ren->SetBackground(0,0,0);<br/><br/> // Render an image (lights and cameras are created automatically)<br/> renWin->Render();<br/><br/> // Begin mouse interaction<br/> iren->Start();<br/>}<br/><br/><span style="font-family:verdana,geneva,sans-serif;">This is the corresponding function "drawCube" 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/> // Create a cube<br/> vtkCubeSource* cube = vtkCubeSource::New();<br/> cube->SetCenter(e*cellSize,-d*cubeHeight,-n*cellSize);<br/> cube->SetXLength(cellSize);<br/> cube->SetYLength(cubeHeight);<br/> cube->SetZLength(cellSize);<br/> <br/> // Create a mapper and actor<br/> vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();<br/> mapper->SetInputConnection(cube->GetOutputPort());<br/> <br/> vtkActor* cubeActor = vtkActor::New();<br/> cubeActor->GetProperty()->SetColor(floor(float(r))/255,floor(float(g))/255,floor(float(b))/255);<br/> cubeActor->SetMapper(mapper);<br/> <br/> m_ren->AddActor(cubeActor);<br/><br/> // Clean-up<br/> cubeActor->Delete();<br/> cube->Delete();<br/> mapper->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/> // Create renderer and render window<br/> m_ren = vtkRenderer::New();<br/> vtkRenderWindow *renWin = vtkRenderWindow::New();<br/> renWin->AddRenderer(m_ren);<br/><br/> // Create interactor<br/> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br/> iren->SetRenderWindow(renWin);<br/><br/> // Create the point structure<br/> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();<br/><br/> // Step through all map cells<br/> for (ushort n=0;n<map.GetMapInfo().cellsNorth; n++)<br/> {<br/> for (ushort e=0;e<map.GetMapInfo().cellsEast; e++)<br/> {<br/> vector<mapData> mapElement = map.getElement(n,e);<br/> for (uint i=0; i<mapElement.size(); i++)<br/> {<br/> if (mapElement[i].isValid())<br/> {<br/><br/> // Setup the coordinates of eight points<br/> // (the two faces must be in counter clockwise order as viewd from the outside)<br/> 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/> 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/> 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/> 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/> 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/> 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/> 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/> 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/> <br/> // Create the points<br/> points->InsertNextPoint(P0);<br/> points->InsertNextPoint(P1);<br/> points->InsertNextPoint(P2);<br/> points->InsertNextPoint(P3);<br/> points->InsertNextPoint(P4);<br/> points->InsertNextPoint(P5);<br/> points->InsertNextPoint(P6);<br/> points->InsertNextPoint(P7);<br/> <br/> }<br/> }<br/> mapElement.clear();<br/> }<br/> }<br/> <br/> <br/> //create the hexahedron<br/> vtkHexahedron * *theHex;<br/> theHex = new vtkHexahedron*[map.getNumberOfFilledCells()];<br/><br/> for(int i=0;i<map.getNumberOfFilledCells();i++)<br/> {<br/> theHex[i] = vtkHexahedron::New();<br/> theHex[i]->GetPointIds()->SetNumberOfIds(8); <br/> for (int j = 0; j <8; j++)<br/> {<br/> theHex[i]->GetPointIds()->SetId(j,j+(i*8)); //this maps internal id 0-7 to global point Id<br/> }<br/> }<br/><br/> //create an unstructured grid for the hexahedron<br/> vtkUnstructuredGrid* theGrid = vtkUnstructuredGrid::New();<br/> theGrid->Allocate(map.getNumberOfFilledCells());<br/> for(int i =0;i<map.getNumberOfFilledCells();i++)<br/> {<br/> theGrid->InsertNextCell(theHex[i]->GetCellType(),<br/> theHex[i]->GetPointIds());<br/> }<br/> theGrid->SetPoints(points);<br/><br/> //create a mapper for the hexahedron<br/> vtkDataSetMapper *theHexMapper;<br/> theHexMapper = vtkDataSetMapper::New();<br/> theHexMapper->SetInput(theGrid);<br/><br/> //create an actor<br/> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();<br/> actor->SetMapper(theHexMapper);<br/> <br/> m_ren->AddActor(actor);<br/><br/> // Set window background color<br/> m_ren->SetBackground(0,0,0);<br/><br/> // Render an image (lights and cameras are created automatically)<br/> renWin->Render();<br/><br/> // Begin mouse interaction<br/> iren->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/> <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ört? WEB.DE hat einen genialen Phishing-Filter in die <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>