void mitk::SurfaceGLMapper2D::Paint(mitk::BaseRenderer * renderer) { bool visible = true; GetDataNode()->GetVisibility(visible, renderer, "visible"); if(!visible) return; Surface::Pointer input = const_cast<Surface*>(this->GetInput()); if(input.IsNull()) return; // // get the TimeGeometry of the input object // const TimeGeometry* inputTimeGeometry = input->GetTimeGeometry(); if(( inputTimeGeometry == NULL ) || ( inputTimeGeometry->CountTimeSteps() == 0 ) ) return; m_LineWidth = 1; GetDataNode()->GetIntProperty("line width", m_LineWidth, renderer); // // get the world time // ScalarType time =renderer->GetTime(); int timestep=0; if( time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin() ) timestep = inputTimeGeometry->TimePointToTimeStep( time ); // int timestep = this->GetTimestep(); if( inputTimeGeometry->IsValidTimeStep( timestep ) == false ) return; vtkPolyData * vtkpolydata = input->GetVtkPolyData( timestep ); if((vtkpolydata==NULL) || (vtkpolydata->GetNumberOfPoints() < 1 )) return; //apply color and opacity read from the PropertyList this->ApplyAllProperties(renderer); if (m_DrawNormals) { m_PointLocator->SetDataSet( vtkpolydata ); m_PointLocator->BuildLocatorFromPoints( vtkpolydata->GetPoints() ); } if(vtkpolydata!=NULL) { Point3D point; Vector3D normal; //Check if Lookup-Table is already given, else use standard one. double* scalarLimits = m_LUT->GetTableRange(); double scalarsMin = scalarLimits[0], scalarsMax = scalarLimits[1]; vtkLookupTable *lut; LookupTableProperty::Pointer lookupTableProp; this->GetDataNode()->GetProperty(lookupTableProp, "LookupTable", renderer); if (lookupTableProp.IsNotNull() ) { lut = lookupTableProp->GetLookupTable()->GetVtkLookupTable(); GetDataNode()->GetDoubleProperty("ScalarsRangeMinimum", scalarsMin, renderer); GetDataNode()->GetDoubleProperty("ScalarsRangeMaximum", scalarsMax, renderer); // check if the scalar range has been changed, e.g. manually, for the data tree node, and rebuild the LUT if necessary. double* oldRange = lut->GetTableRange(); if( oldRange[0] != scalarsMin || oldRange[1] != scalarsMax ) { lut->SetTableRange(scalarsMin, scalarsMax); lut->Build(); } } else { lut = m_LUT; } vtkLinearTransform * vtktransform = GetDataNode()->GetVtkTransform(timestep); PlaneGeometry::ConstPointer worldGeometry = renderer->GetCurrentWorldPlaneGeometry(); assert( worldGeometry.IsNotNull() ); if (worldGeometry.IsNotNull()) { // set up vtkPlane according to worldGeometry point=worldGeometry->GetOrigin(); normal=worldGeometry->GetNormal(); normal.Normalize(); m_Plane->SetTransform((vtkAbstractTransform*)NULL); } else { AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldPlaneGeometry()); if(worldAbstractGeometry.IsNotNull()) { AbstractTransformGeometry::ConstPointer surfaceAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(input->GetTimeGeometry()->GetGeometryForTimeStep(0).GetPointer()); if(surfaceAbstractGeometry.IsNotNull()) //@todo substitude by operator== after implementation, see bug id 28 { PaintCells(renderer, vtkpolydata, worldGeometry, renderer->GetDisplayGeometry(), vtktransform, lut); return; } else { //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "flat plane" into a "curved plane"? return; // set up vtkPlane according to worldGeometry point=const_cast<BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum(); FillVector3D(normal, 0, 0, 1); m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse()); } } else return; } double vp[3], vnormal[3]; vnl2vtk(point.GetVnlVector(), vp); vnl2vtk(normal.GetVnlVector(), vnormal); //normally, we would need to transform the surface and cut the transformed surface with the cutter. //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead. //@todo It probably does not work for scaling operations yet:scaling operations have to be //dealed with after the cut is performed by scaling the contour. vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse(); inversetransform->TransformPoint(vp, vp); inversetransform->TransformNormalAtPoint(vp, vnormal, vnormal); m_Plane->SetOrigin(vp); m_Plane->SetNormal(vnormal); //set data into cutter m_Cutter->SetInputData(vtkpolydata); m_Cutter->Update(); // m_Cutter->GenerateCutScalarsOff(); // m_Cutter->SetSortByToSortByCell(); if (m_DrawNormals) { m_Stripper->SetInputData( m_Cutter->GetOutput() ); // calculate the cut m_Stripper->Update(); PaintCells(renderer, m_Stripper->GetOutput(), worldGeometry, renderer->GetDisplayGeometry(), vtktransform, lut, vtkpolydata); } else { PaintCells(renderer, m_Cutter->GetOutput(), worldGeometry, renderer->GetDisplayGeometry(), vtktransform, lut, vtkpolydata); } } }
LRESULT CALLBACK MainWndProc(HWND Wnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC WindowDC; switch(msg) { case WM_PAINT: WindowDC = BeginPaint(Wnd, &ps); PaintCells(WindowDC, 4, 4, 0, 0); PaintCells(WindowDC, 4, 8, 5 * CELL_SIZE, 0); PaintCells(WindowDC, 4, 16, 10 * CELL_SIZE, 0); PaintCells(WindowDC, 4, 24, 15 * CELL_SIZE, 0); PaintCells(WindowDC, 4, 32, 20 * CELL_SIZE, 0); PaintCells(WindowDC, 8, 4, 0, 5 * CELL_SIZE); PaintCells(WindowDC, 8, 8, 5 * CELL_SIZE, 5 * CELL_SIZE); PaintCells(WindowDC, 8, 16, 10 * CELL_SIZE, 5 * CELL_SIZE); PaintCells(WindowDC, 8, 24, 15 * CELL_SIZE, 5 * CELL_SIZE); PaintCells(WindowDC, 8, 32, 20 * CELL_SIZE, 5 * CELL_SIZE); PaintCells(WindowDC, 16, 4, 0, 10 * CELL_SIZE); PaintCells(WindowDC, 16, 8, 5 * CELL_SIZE, 10 * CELL_SIZE); PaintCells(WindowDC, 16, 16, 10 * CELL_SIZE, 10 * CELL_SIZE); PaintCells(WindowDC, 16, 24, 15 * CELL_SIZE, 10 * CELL_SIZE); PaintCells(WindowDC, 16, 32, 20 * CELL_SIZE, 10 * CELL_SIZE); PaintCells(WindowDC, 24, 4, 0, 15 * CELL_SIZE); PaintCells(WindowDC, 24, 8, 5 * CELL_SIZE, 15 * CELL_SIZE); PaintCells(WindowDC, 24, 16, 10 * CELL_SIZE, 15 * CELL_SIZE); PaintCells(WindowDC, 24, 24, 15 * CELL_SIZE, 15 * CELL_SIZE); PaintCells(WindowDC, 24, 32, 20 * CELL_SIZE, 15 * CELL_SIZE); PaintCells(WindowDC, 32, 4, 0, 20 * CELL_SIZE); PaintCells(WindowDC, 32, 8, 5 * CELL_SIZE, 20 * CELL_SIZE); PaintCells(WindowDC, 32, 16, 10 * CELL_SIZE, 20 * CELL_SIZE); PaintCells(WindowDC, 32, 24, 15 * CELL_SIZE, 20 * CELL_SIZE); PaintCells(WindowDC, 32, 32, 20 * CELL_SIZE, 20 * CELL_SIZE); EndPaint(Wnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(Wnd, msg, wParam, lParam); } return 0; }