diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper2D.cpp b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper2D.cpp index ed3aecd0e4..0ede32cfc0 100644 --- a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper2D.cpp +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper2D.cpp @@ -1,316 +1,316 @@ /* * mitkFiberBundleMapper2D.cpp * mitk-all * * Created by HAL9000 on 1/17/11. * Copyright 2011 __MyCompanyName__. All rights reserved. * */ #include "mitkFiberBundleMapper2D.h" #include #include "mitkFiberBundleMapper3D.h" #include #include #include #include //#include //#include #include #include #include #include #include #include #include #include //#include #include #include #include #include #include mitk::FiberBundleMapper2D::FiberBundleMapper2D() { } mitk::FiberBundleMapper2D::~FiberBundleMapper2D() { } const mitk::FiberBundle* mitk::FiberBundleMapper2D::GetInput() { return dynamic_cast ( GetData() ); } void mitk::FiberBundleMapper2D::Update(mitk::BaseRenderer * renderer) { if ( !this->IsVisible( renderer ) ) { return; } // Calculate time step of the input data for the specified renderer (integer value) // this method is implemented in mitkMapper this->CalculateTimeStep( renderer ); //check if updates occured in the node or on the display FBLocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); const DataNode *node = this->GetDataNode(); if ( (localStorage->m_LastUpdateTime < node->GetMTime()) || (localStorage->m_LastUpdateTime < node->GetPropertyList()->GetMTime()) //was a property modified? || (localStorage->m_LastUpdateTime < node->GetPropertyList(renderer)->GetMTime()) ) { MITK_INFO << "UPDATE NEEDED FOR _ " << renderer->GetName(); this->GenerateDataForRenderer( renderer ); } if ((localStorage->m_LastUpdateTime < renderer->GetDisplayGeometry()->GetMTime()) ) //was the display geometry modified? e.g. zooming, panning) { this->UpdateShaderParameter(renderer); } } void mitk::FiberBundleMapper2D::UpdateShaderParameter(mitk::BaseRenderer * renderer) { FBLocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); // MITK_INFO << "uSERWAAAAAAAS, da shader brauchat a poor neue zoin"; //get information about current position of views mitk::SliceNavigationController::Pointer sliceContr = renderer->GetSliceNavigationController(); mitk::PlaneGeometry::ConstPointer planeGeo = sliceContr->GetCurrentPlaneGeometry(); //generate according cutting planes based on the view position float sliceN[3], planeOrigin[3]; // since shader uses camera coordinates, transform origin and normal from worldcoordinates to cameracoordinates planeOrigin[0] = (float) planeGeo->GetOrigin()[0]; planeOrigin[1] = (float) planeGeo->GetOrigin()[1]; planeOrigin[2] = (float) planeGeo->GetOrigin()[2]; sliceN[0] = planeGeo->GetNormal()[0]; sliceN[1] = planeGeo->GetNormal()[1]; sliceN[2] = planeGeo->GetNormal()[2]; float tmp1 = planeOrigin[0] * sliceN[0]; float tmp2 = planeOrigin[1] * sliceN[1]; float tmp3 = planeOrigin[2] * sliceN[2]; float d1 = tmp1 + tmp2 + tmp3; //attention, correct normalvector float plane1[4]; plane1[0] = sliceN[0]; plane1[1] = sliceN[1]; plane1[2] = sliceN[2]; plane1[3] = d1; float thickness = 2.0; if(!this->GetDataNode()->GetPropertyValue("Fiber2DSliceThickness",thickness)) MITK_INFO << "FIBER2D SLICE THICKNESS PROPERTY ERROR"; bool fiberfading = false; if(!this->GetDataNode()->GetPropertyValue("Fiber2DfadeEFX",fiberfading)) MITK_INFO << "FIBER2D SLICE FADE EFX PROPERTY ERROR"; int fiberfading_i = 1; if (!fiberfading) fiberfading_i = 0; localStorage->m_PointActor->GetProperty()->AddShaderVariable("slicingPlane",4, plane1); localStorage->m_PointActor->GetProperty()->AddShaderVariable("fiberThickness",1, &thickness); localStorage->m_PointActor->GetProperty()->AddShaderVariable("fiberFadingON",1, &fiberfading_i); } // ALL RAW DATA FOR VISUALIZATION IS GENERATED HERE. // vtkActors and Mappers are feeded here void mitk::FiberBundleMapper2D::GenerateDataForRenderer(mitk::BaseRenderer *renderer) { MITK_INFO << "FiberBundlemapper2D _ GENERATE DATA"; //the handler of local storage gets feeded in this method with requested data for related renderwindow FBLocalStorage *localStorage = m_LSH.GetLocalStorage(renderer); //this procedure is depricated, //not needed after initializaton anymore mitk::DataNode* node = this->GetDataNode(); if ( node == NULL ) { MITK_INFO << "check DATANODE: ....[Fail] "; return; } /////////////////////////////////// mitk::FiberBundleMapper3D::Pointer FBMapper3D = dynamic_cast< mitk::FiberBundleMapper3D* > (node->GetMapper( 2 )); if ( FBMapper3D->GetInput() == NULL ) { MITK_INFO << "check FBMapper3D Input: ....[Fail] "; return; } //feed local storage with data we want to visualize // localStorage->m_SlicedResult = FBMapper3D->GetCut(planeOrigin, planeN, cutParams); // localStorage->m_SlicedResult = FBMapper3D->GetVtkFBPolyDataMapper(); localStorage->m_SlicedResult = (vtkPolyData*) FBMapper3D->getVtkFiberBundleMapper()->GetInputAsDataSet(); //MITK_INFO << renderer->GetName() << " OutputPoints#: " << localStorage->m_SlicedResult->GetNumberOfPoints(); - vtkLookupTable *lut = vtkLookupTable::New(); + vtkSmartPointer lut = vtkLookupTable::New(); lut->Build(); localStorage->m_PointMapper->SetScalarModeToUsePointFieldData(); //m_VtkFiberDataMapperGL->SelectColorArray("FaColors"); localStorage->m_PointMapper->SelectColorArray("ColorValues"); localStorage->m_PointMapper->SetLookupTable(lut); //apply the properties after the slice was set //this->ApplyProperties( renderer ); //setup the camera according to the actor with zooming/panning etc. // this->AdjustCamera( renderer, planeGeo ); // feed the vtk fiber mapper with point data ...TODO do in constructor localStorage->m_PointMapper->SetInput(localStorage->m_SlicedResult); // in optimized version, mapper is feeded by localStorage->m_cutter->GetOutput(); localStorage->m_PointActor->SetMapper(localStorage->m_PointMapper); localStorage->m_PointActor->GetProperty()->ShadingOn(); // Applying shading properties { //Superclass::ApplyProperties( ls->m_Actor, renderer ) ; // VTK Properties //ApplyMitkPropertiesToVtkProperty( this->GetDataNode(), ls->m_Actor->GetProperty(), renderer ); // Shaders mitk::ShaderRepository::GetGlobalShaderRepository()->ApplyProperties(this->GetDataNode(),localStorage->m_PointActor,renderer, localStorage->m_LastUpdateTime); } this->UpdateShaderParameter(renderer); // We have been modified => save this for next Update() localStorage->m_LastUpdateTime.Modified(); } vtkProp* mitk::FiberBundleMapper2D::GetVtkProp(mitk::BaseRenderer *renderer) { //MITK_INFO << "FiberBundleMapper2D GetVtkProp(renderer)"; this->Update(renderer); return m_LSH.GetLocalStorage(renderer)->m_PointActor; } void mitk::FiberBundleMapper2D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { //add shader to datano //####### load shader from file ######### std::string m_VolumeDir = MITK_ROOT; m_VolumeDir += "Modules/DiffusionImaging/Rendering/"; mitk::StandardFileLocations::GetInstance()->AddDirectoryForSearch( m_VolumeDir.c_str(), false ); mitk::ShaderRepository::Pointer shaderRepository = mitk::ShaderRepository::GetGlobalShaderRepository(); shaderRepository->LoadShader(mitk::StandardFileLocations::GetInstance()->FindFile("mitkShaderFiberClipping.xml")); //#################################################################### node->SetProperty("shader",mitk::ShaderProperty::New("mitkShaderFiberClipping")); mitk::ShaderRepository::GetGlobalShaderRepository()->AddDefaultProperties(node,renderer,overwrite); //add other parameters to propertylist node->AddProperty( "Fiber2DSliceThickness", mitk::FloatProperty::New(2.0f), renderer, overwrite ); node->AddProperty( "Fiber2DfadeEFX", mitk::BoolProperty::New(true), renderer, overwrite ); Superclass::SetDefaultProperties(node, renderer, overwrite); } // following methods are essential, they actually call the GetVtkProp() method // which returns the desired actors void mitk::FiberBundleMapper2D::MitkRenderOverlay(BaseRenderer* renderer) { // MITK_INFO << "FiberBundleMapper2D MitkRenderOVerlay(renderer)"; if ( this->IsVisible(renderer)==false ) return; if ( this->GetVtkProp(renderer)->GetVisibility() ) { this->GetVtkProp(renderer)->RenderOverlay(renderer->GetVtkRenderer()); } } void mitk::FiberBundleMapper2D::MitkRenderOpaqueGeometry(BaseRenderer* renderer) { // MITK_INFO << "FiberBundleMapper2D MitkRenderOpaqueGeometry(renderer)"; if ( this->IsVisible( renderer )==false ) return; if ( this->GetVtkProp(renderer)->GetVisibility() ) this->GetVtkProp(renderer)->RenderOpaqueGeometry( renderer->GetVtkRenderer() ); } void mitk::FiberBundleMapper2D::MitkRenderTranslucentGeometry(BaseRenderer* renderer) { // MITK_INFO << "FiberBundleMapper2D MitkRenderTranslucentGeometry(renderer)"; if ( this->IsVisible(renderer)==false ) return; //TODO is it possible to have a visible BaseRenderer AND an invisible VtkRenderer??? if ( this->GetVtkProp(renderer)->GetVisibility() ) this->GetVtkProp(renderer)->RenderTranslucentPolygonalGeometry(renderer->GetVtkRenderer()); } void mitk::FiberBundleMapper2D::MitkRenderVolumetricGeometry(BaseRenderer* renderer) { // MITK_INFO << "FiberBundleMapper2D MitkRenderVolumentricGeometry(renderer)"; if(IsVisible(renderer)==false) return; //TODO is it possible to have a visible BaseRenderer AND an invisible VtkRenderer??? if ( GetVtkProp(renderer)->GetVisibility() ) this->GetVtkProp(renderer)->RenderVolumetricGeometry(renderer->GetVtkRenderer()); } mitk::FiberBundleMapper2D::FBLocalStorage::FBLocalStorage() { m_PointActor = vtkSmartPointer::New(); m_PointMapper = vtkSmartPointer::New(); } \ No newline at end of file diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.cpp b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.cpp index 6b981895c1..61891c55b4 100644 --- a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.cpp +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.cpp @@ -1,773 +1,758 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 17179 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "mitkProperties.h" +#include #include "mitkFiberBundleMapper3D.h" #include #include #include #include #include #include #include -#include -#include -#include -#include -#include "vtkVertex.h" -#include + #include #include #include #include #include "mitkFiberBundleInteractor.h" -#include "mitkGlobalInteraction.h" +#include //template mitk::FiberBundleMapper3D::FiberBundleMapper3D() -: m_vtkFiberList(NULL), -//m_VtkFiberDataMapperGL(NULL), - m_VtkFiberDataMapperGL(vtkOpenGLPolyDataMapper::New()), -m_vtkTubeMapper(NULL) - +: m_VtkFiberDataMapperGL(vtkOpenGLPolyDataMapper::New()) +, m_FiberActor(vtkOpenGLActor::New()) +, m_FiberAssembly(vtkPropAssembly::New()) +, m_vtkTubeMapper(vtkOpenGLPolyDataMapper::New()) +, m_tubes(vtkTubeFilter::New()) +, m_TubeActor(vtkOpenGLActor::New()) { - MITK_INFO << "FiberBundleMapper3D()"; - m_FiberAssembly = vtkPropAssembly::New(); - m_FiberActor = vtkOpenGLActor::New(); - m_TubeActor = vtkOpenGLActor::New(); - + + } -//template mitk::FiberBundleMapper3D::~FiberBundleMapper3D() { - MITK_INFO << "FiberBundleMapper3D(destructor)"; - m_FiberActor->Delete(); - m_FiberAssembly->Delete(); - //m_vtkFiberList->Delete(); - //m_VtkFiberDataMapperGL->Delete(); - //m_VtkFiberDataMapper->Delete(); - + } const mitk::FiberBundle* mitk::FiberBundleMapper3D::GetInput() { //MITK_INFO << "FiberBundleMapper3D GetInput()" ; return static_cast ( GetData() ); } vtkOpenGLPolyDataMapper* mitk::FiberBundleMapper3D::getVtkFiberBundleMapper() { return m_VtkFiberDataMapperGL; } /* This method is called once the mapper gets new input, for UI rotation or changes in colorcoding this method is NOT called */ void mitk::FiberBundleMapper3D::GenerateData() { /* ######## FIBER PREPARATION START ######### */ //get fiberbundle mitk::FiberBundle::Pointer PFiberBundle = dynamic_cast< mitk::FiberBundle* > (this->GetData()); //get groupFiberBundle, which is a datastructure containing single fibers mitk::FiberBundle::FiberGroupType::Pointer groupFiberBundle = PFiberBundle->GetGroupFiberBundle(); //extractn single fibers //in the groupFiberBundle all smartPointers to single fibers are stored in in a ChildrenList mitk::FiberBundle::ChildrenListType * FiberList; FiberList = groupFiberBundle->GetChildren(); /* ######## FIBER PREPARATION END ######### */ /* ######## VTK FIBER REPRESENTATION ######## */ //create a vtkPoints object and store the all the brainFiber points in it - vtkPoints* vtkSmoothPoints = vtkPoints::New(); //in smoothpoints the interpolated points representing a fiber are stored. + vtkSmartPointer vtkSmoothPoints = vtkPoints::New(); //in smoothpoints the interpolated points representing a fiber are stored. //in vtkcells all polylines are stored, actually all id's of them are stored - vtkCellArray *vtkSmoothCells = vtkCellArray::New(); //cellcontainer for smoothed lines + vtkSmartPointer vtkSmoothCells = vtkCellArray::New(); //cellcontainer for smoothed lines //in some cases a fiber includes just 1 point, so put it in here - vtkCellArray *vtkVrtxs = vtkCellArray::New(); + vtkSmartPointer vtkVrtxs = vtkCellArray::New(); //colors and alpha value for each single point, RGBA = 4 components - vtkUnsignedCharArray *colorsT = vtkUnsignedCharArray::New(); + vtkSmartPointer colorsT = vtkUnsignedCharArray::New(); colorsT->SetNumberOfComponents(4); colorsT->SetName("ColorValues"); - vtkDoubleArray *faColors = vtkDoubleArray::New(); + vtkSmartPointer faColors = vtkDoubleArray::New(); faColors->SetName("FaColors"); - vtkDoubleArray *tubeRadius = vtkDoubleArray::New(); + vtkSmartPointer tubeRadius = vtkDoubleArray::New(); tubeRadius->SetName("TubeRadius"); // iterate through FiberList for(mitk::FiberBundle::ChildrenListType::iterator itLst = FiberList->begin(); itLst != FiberList->end(); ++itLst) { //all points are stored in one vtkpoints list, soooooooo that the lines find their point id to start and end we need some kind of helper index who monitors the current ids for a polyline //unsigned long pntIdxHelper = vtkpointsDTI->GetNumberOfPoints(); // lists output is SpatialObject, we know we have DTITubeSpacialObjects // dynamic cast only likes pointers, no smartpointers, so each dsmartpointer has membermethod .GetPointer() itk::SpatialObject<3>::Pointer tmp_fbr; tmp_fbr = *itLst; mitk::FiberBundle::DTITubeType::Pointer dtiTract = dynamic_cast< mitk::FiberBundle::DTITubeType * > (tmp_fbr.GetPointer()); if (dtiTract.IsNull()) { return; } //get list of points int fibrNrPnts = dtiTract->GetNumberOfPoints(); mitk::FiberBundle::DTITubeType::PointListType dtiPntList = dtiTract->GetPoints(); //MITK_INFO << "REAL AMOUNT OF FIBERS: " << fibrNrPnts; - vtkPoints *vtkpointsDTI = vtkPoints::New(); + vtkSmartPointer vtkpointsDTI = vtkPoints::New(); if (fibrNrPnts <= 0) { //this should never occour! but who knows MITK_INFO << "HyperERROR in fiberBundleMapper3D.cpp ...no point in fiberBundle!!! .. check ur trackingAlgorithm"; continue; } ///////PROCESS ON FIBERS//////// for (int i=0; i1 PFiberBundle->GetGeometry()->IndexToWorld(indexPnt, worldPnt); double worldFbrPnt[3] = {worldPnt[0], worldPnt[1], worldPnt[2]}; vtkpointsDTI->InsertNextPoint(worldFbrPnt); } //MITK_INFO << "REDUCED AMOUNT OF FIBERS: " << vtkpointsDTI->GetNumberOfPoints(); ////POINTS OF DTI ARE READY FOR FUTHER VTK PROCESSING//// } /////PROCESS POLYLINE SMOOTHING///// - vtkKochanekSpline* xSpline = vtkKochanekSpline::New(); - vtkKochanekSpline* ySpline = vtkKochanekSpline::New(); - vtkKochanekSpline* zSpline = vtkKochanekSpline::New(); + vtkSmartPointer xSpline = vtkKochanekSpline::New(); + vtkSmartPointer ySpline = vtkKochanekSpline::New(); + vtkSmartPointer zSpline = vtkKochanekSpline::New(); - vtkParametricSpline* spline = vtkParametricSpline::New(); + vtkSmartPointer spline = vtkParametricSpline::New(); spline->SetXSpline(xSpline); spline->SetYSpline(ySpline); spline->SetZSpline(zSpline); spline->SetPoints(vtkpointsDTI); - vtkParametricFunctionSource* functionSource = vtkParametricFunctionSource::New(); + vtkSmartPointer functionSource = vtkParametricFunctionSource::New(); functionSource->SetParametricFunction(spline); functionSource->SetUResolution(200); functionSource->SetVResolution(200); functionSource->SetWResolution(200); functionSource->Update(); vtkPolyData* outputFunction = functionSource->GetOutput(); vtkPoints* tmpSmoothPnts = outputFunction->GetPoints(); //smoothPoints of current fiber - vtkPolyLine* smoothLine = vtkPolyLine::New(); + vtkSmartPointer smoothLine = vtkPolyLine::New(); smoothLine->GetPointIds()->SetNumberOfIds(tmpSmoothPnts->GetNumberOfPoints()); // MITK_INFO << "SMOOTHED AMOUNT OF POINTS:" << tmpSmoothPnts->GetNumberOfPoints(); /////CREATE SMOOTH POLYLINE OBJECT//// /////MANAGE LINE AND CORRELATED POINTS///// int pointHelperCnt = vtkSmoothPoints->GetNumberOfPoints(); //also put current points into global smooth pointcontainer int nrSmPnts = tmpSmoothPnts->GetNumberOfPoints(); tubeRadius->SetNumberOfTuples(nrSmPnts); double tbradius = 1;//default value for radius for(int ism=0; ismGetPointIds()->SetId(ism, ism+pointHelperCnt); vtkSmoothPoints->InsertNextPoint(tmpSmoothPnts->GetPoint(ism)); // MITK_INFO << "LinePntID: " << ism << " linked to: " << ism+pointHelperCnt << " val: " << tmpSmoothPnts->GetPoint(ism)[0] << " " << tmpSmoothPnts->GetPoint(ism)[1] << " " << tmpSmoothPnts->GetPoint(ism)[2]; tubeRadius->SetTuple1(ism,tbradius); //tuple with 1 argument //colorcoding orientation based unsigned char rgba[4] = {0,0,0,0}; if (ism < nrSmPnts-1 && ism>0) { // MITK_INFO << "inbetween fiber, at position:" << ism; // //nimm nur diff1 vnl_vector_fixed< double, 3 > tmpPntvtk(tmpSmoothPnts->GetPoint(ism)[0], tmpSmoothPnts->GetPoint(ism)[1],tmpSmoothPnts->GetPoint(ism)[2]); vnl_vector_fixed< double, 3 > nxttmpPntvtk(tmpSmoothPnts->GetPoint(ism+1)[0], tmpSmoothPnts->GetPoint(ism+1)[1], tmpSmoothPnts->GetPoint(ism+1)[2]); vnl_vector_fixed< double, 3 > prevtmpPntvtk(tmpSmoothPnts->GetPoint(ism-1)[0], tmpSmoothPnts->GetPoint(ism-1)[1], tmpSmoothPnts->GetPoint(ism-1)[2]); vnl_vector_fixed< double, 3 > diff1; diff1 = tmpPntvtk - nxttmpPntvtk; diff1.normalize(); vnl_vector_fixed< double, 3 > diff2; diff2 = tmpPntvtk - prevtmpPntvtk; diff2.normalize(); vnl_vector_fixed< double, 3 > diff; diff = (diff1 - diff2)/2.0; rgba[0] = (unsigned char) (255.0 * std::abs(diff[0])); rgba[1] = (unsigned char) (255.0 * std::abs(diff[1])); rgba[2] = (unsigned char) (255.0 * std::abs(diff[2])); rgba[3] = (unsigned char) (255.0); } else if(ism==0) { //explicit handling of startpoint of line //nimm nur diff1 vnl_vector_fixed< double, 3 > tmpPntvtk(tmpSmoothPnts->GetPoint(ism)[0], tmpSmoothPnts->GetPoint(ism)[1],tmpSmoothPnts->GetPoint(ism)[2]); vnl_vector_fixed< double, 3 > nxttmpPntvtk(tmpSmoothPnts->GetPoint(ism+1)[0], tmpSmoothPnts->GetPoint(ism+1)[1], tmpSmoothPnts->GetPoint(ism+1)[2]); vnl_vector_fixed< double, 3 > diff1; diff1 = tmpPntvtk - nxttmpPntvtk; diff1.normalize(); rgba[0] = (unsigned char) (255.0 * std::abs(diff1[0])); rgba[1] = (unsigned char) (255.0 * std::abs(diff1[1])); rgba[2] = (unsigned char) (255.0 * std::abs(diff1[2])); rgba[3] = (unsigned char) (255.0); // MITK_INFO << "first point color: " << rgba[0] << " " << rgba[1] << " " << rgba[2]; } else if(ism==nrSmPnts-1) { // last point in fiber // nimm nur diff2 vnl_vector_fixed< double, 3 > tmpPntvtk(tmpSmoothPnts->GetPoint(ism)[0], tmpSmoothPnts->GetPoint(ism)[1],tmpSmoothPnts->GetPoint(ism)[2]); vnl_vector_fixed< double, 3 > prevtmpPntvtk(tmpSmoothPnts->GetPoint(ism-1)[0], tmpSmoothPnts->GetPoint(ism-1)[1], tmpSmoothPnts->GetPoint(ism-1)[2]); vnl_vector_fixed< double, 3 > diff2; diff2 = tmpPntvtk - prevtmpPntvtk; diff2.normalize(); rgba[0] = (unsigned char) (255.0 * std::abs(diff2[0])); rgba[1] = (unsigned char) (255.0 * std::abs(diff2[1])); rgba[2] = (unsigned char) (255.0 * std::abs(diff2[2])); rgba[3] = (unsigned char) (255.0); // // MITK_INFO << "last point color: " << rgba[0] << " " << rgba[1] << " " << rgba[2]; } //end colorcoding // colorsT->InsertNextTupleValue(rgba); }//end of smoothline ///////smooth Fiber ready//////// vtkSmoothCells->InsertNextCell(smoothLine); } //vtkpointsDTI->Delete();//points are not needed anymore TODO uncomment! /* //get FA value ... for that FA has to be interpolated as well as DTItracktLine float faVal = tmpFiberPntLst.GetField(mitk::FiberBundle::DTITubePointType::FA); //use insertNextValue cuz FA Values are reperesented as a single number (1 Tuple containing 1 parameter) faColors->InsertNextValue((double) faVal); */ //vtkcells->InitTraversal(); // Put points and lines together in one polyData structure - vtkPolyData *polyData = vtkPolyData::New(); + vtkSmartPointer polyData = vtkPolyData::New(); polyData->SetPoints(vtkSmoothPoints); polyData->SetLines(vtkSmoothCells); if (vtkVrtxs->GetSize() > 0) { polyData->SetVerts(vtkVrtxs); } polyData->GetPointData()->AddArray(colorsT); //polyData->GetPointData()->AddArray(faColors); //polyData->GetPointData()->AddArray(tubeRadius); - vtkLookupTable *lut = vtkLookupTable::New(); + vtkSmartPointer lut = vtkLookupTable::New(); lut->Build(); // m_VtkFiberDataMapperGL = vtkOpenGLPolyDataMapper::New(); m_VtkFiberDataMapperGL->SetInput(polyData); m_VtkFiberDataMapperGL->ScalarVisibilityOn(); m_VtkFiberDataMapperGL->SetScalarModeToUsePointFieldData(); //m_VtkFiberDataMapperGL->SelectColorArray("FaColors"); m_VtkFiberDataMapperGL->SelectColorArray("ColorValues"); m_VtkFiberDataMapperGL->SetLookupTable(lut); - - m_vtkTubeMapper = vtkOpenGLPolyDataMapper::New(); + //m_FiberActor = vtkOpenGLActor::New(); m_FiberActor->SetMapper(m_VtkFiberDataMapperGL); m_FiberActor->GetProperty()->SetOpacity(1.0); m_FiberActor->GetProperty()->SetPointSize(4.0f); // m_FiberActor->GetProperty()->SetColor(255.0, 0.0, 0.0); m_FiberAssembly->AddPart(m_FiberActor); //setting color and opacity in the fiberActor itself is not recommended //here cuz color and opacity of dataNode will be considered in GetData(baserenderer*) anyway this->GetDataNode()->SetColor(255.0,0,0); this->GetDataNode()->SetOpacity(1.0); } //template void mitk::FiberBundleMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) { // nodeCC = 1 ... ROI colorcoding // 2 ... orientation colorcoding // 3 ... FA colorcoding int nodeCC; bool isCCd = this->GetDataNode()->GetPropertyValue("ColorCoding", nodeCC); if ( isCCd && nodeCC == 1 ) { //get color and opacity from DataNode int tmpline; bool isLineProp = this->GetDataNode()->GetPropertyValue("LineWidth",tmpline); bool isPointRep; bool successPointProp = this->GetDataNode()->GetPropertyValue("RepPoints", isPointRep); float pointSize; bool successPointSize = this->GetDataNode()->GetPropertyValue("pointSize", pointSize); if (isLineProp) { m_FiberActor->GetProperty()->SetLineWidth(tmpline); } if(isPointRep) { m_FiberActor->GetProperty()->SetRepresentationToPoints(); m_FiberActor->GetProperty()->SetPointSize(pointSize); } } else if (isCCd && nodeCC == 2) { float tmpopa; this->GetDataNode()->GetOpacity(tmpopa, NULL); m_FiberActor->GetProperty()->SetOpacity((double) tmpopa); } else if (isCCd && nodeCC == 3) { float temprgb[3]; this->GetDataNode()->GetColor( temprgb, NULL ); double trgb[3] = { (double) temprgb[0], (double) temprgb[1], (double) temprgb[2] }; m_FiberActor->GetProperty()->SetColor(trgb); if(m_VtkFiberDataMapperGL->GetScalarVisibility()) //can be 0 or 1, for scalarVis On or Off { m_VtkFiberDataMapperGL->ScalarVisibilityOff(); } } else if (isCCd && nodeCC == 4) { if(!m_VtkFiberDataMapperGL->GetScalarVisibility()) //can be 0 or 1, for scalarVis On or Off { m_VtkFiberDataMapperGL->ScalarVisibilityOn(); } m_VtkFiberDataMapperGL->SelectColorArray("ColorValues"); } else if (isCCd && nodeCC == 5){ if(!m_VtkFiberDataMapperGL->GetScalarVisibility()) //if visibility is off, switch it on { m_VtkFiberDataMapperGL->ScalarVisibilityOn(); } m_VtkFiberDataMapperGL->SelectColorArray("FaColors"); } else if (isCCd && nodeCC == 6){ //orientationbased colorcoding + FA as opacity //get FA out of polydata, which is saved in faColor vtkDoubleArray vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); vtkPointData *tmpPointData = tmpPolyData->GetPointData(); int hasAr = tmpPointData->HasArray("FaColors"); if(!hasAr) return; vtkDoubleArray *tmpFAarray = (vtkDoubleArray*)(tmpPointData->GetArray("FaColors")) ; /*for(int i=0; iGetNumberOfTuples(); i++) { double *tmpTuple; tmpFAarray->GetTuple(i, tmpTuple); for(int j=0; jGetNumberOfComponents(); j++) { MITK_INFO << "FA Value: at index " << i << ": " << tmpTuple[j]; } } */ //since we have our FA values, lets replace the alpha values in colorT //we know each 4th entry is a A value of RGBA int hasArCV = tmpPointData->HasArray("ColorValues"); if(!hasArCV) return; vtkUnsignedCharArray *colorsTtmp = dynamic_cast (tmpPointData->GetArray("ColorValues")); for(int i=0; iGetNumberOfTuples(); i++) { //double *tmpTupleCV = colorsTtmp->GetTuple4(i); double tmpTupleFA = tmpFAarray->GetTuple1(i); tmpTupleFA = tmpTupleFA * 255.0; colorsTtmp->SetComponent(i,3, tmpTupleFA ); // MITK_INFO << "----" << i; //MITK_INFO << tmpTupleCV[0]; //MITK_INFO << tmpTupleCV[1]; //MITK_INFO << tmpTupleCV[2]; //MITK_INFO << tmpTupleCV[3]; //double *test = m_VtkFiberDataMapperGL->GetInput()->GetPointData()->GetArray("ColorValues")->GetTuple4(i); //MITK_INFO << test[0]; //MITK_INFO << test[1]; //MITK_INFO << test[2]; //MITK_INFO << test[3]; } m_VtkFiberDataMapperGL->SelectColorArray(""); m_VtkFiberDataMapperGL->SelectColorArray("ColorValues"); } else if (isCCd && nodeCC == 7){ vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); vtkPointData *tmpPointData = tmpPolyData->GetPointData(); int hasArCV = tmpPointData->HasArray("ColorValues"); if(!hasArCV) return; vtkUnsignedCharArray *colorsTtmp = dynamic_cast (tmpPointData->GetArray("ColorValues")); for(int i=0; iGetNumberOfTuples(); i++) { double tmpTupleFA = 255.0; colorsTtmp->SetComponent(i,3, tmpTupleFA ); } m_VtkFiberDataMapperGL->SelectColorArray(""); m_VtkFiberDataMapperGL->SelectColorArray("ColorValues"); } else if (isCCd && nodeCC == 8) { /* something is still missing to activate smoothing or make it work.... */ if (!renderer->GetRenderWindow()->GetLineSmoothing()) { renderer->GetRenderWindow()->SetLineSmoothing(1); renderer->GetRenderWindow()->Modified(); } if (!renderer->GetRenderWindow()->GetPointSmoothing()) { renderer->GetRenderWindow()->SetPointSmoothing(1); renderer->GetRenderWindow()->Modified(); } if (!renderer->GetRenderWindow()->GetPolygonSmoothing()) { renderer->GetRenderWindow()->SetPolygonSmoothing(1); renderer->GetRenderWindow()->Modified(); } } else if (isCCd && nodeCC == 9) { if (renderer->GetRenderWindow()->GetLineSmoothing()) { renderer->GetRenderWindow()->SetLineSmoothing(0); renderer->GetRenderWindow()->Modified(); } if (renderer->GetRenderWindow()->GetPointSmoothing()) { renderer->GetRenderWindow()->SetPointSmoothing(0); renderer->GetRenderWindow()->Modified(); } if (renderer->GetRenderWindow()->GetPolygonSmoothing()) { renderer->GetRenderWindow()->SetPolygonSmoothing(0); renderer->GetRenderWindow()->Modified(); } } else if (isCCd && nodeCC == 10) { // manipulate X Coordinates of selected FiberBundle int tmpXmove; bool isXmove = this->GetDataNode()->GetPropertyValue("Xmove",tmpXmove); if (!isXmove) return; vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); vtkPoints* tmpVtkPnts = tmpPolyData->GetPoints(); double PtmpPntVal[3]; for (int i=0; iGetNumberOfPoints(); ++i ) { tmpVtkPnts->GetPoint(i,PtmpPntVal); PtmpPntVal[0] = PtmpPntVal[0] + (double) tmpXmove; tmpVtkPnts->SetPoint(i, PtmpPntVal); tmpPolyData->Modified(); } } else if (isCCd && nodeCC == 11) { // manipulate Y Coordinates of selected FiberBundle int tmpYmove; bool isYmove = this->GetDataNode()->GetPropertyValue("Ymove",tmpYmove); if (!isYmove) return; vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); vtkPoints* tmpVtkPnts = tmpPolyData->GetPoints(); double PtmpPntVal[3]; for (int i=0; iGetNumberOfPoints(); ++i ) { tmpVtkPnts->GetPoint(i,PtmpPntVal); PtmpPntVal[1] = PtmpPntVal[1] + (double) tmpYmove; tmpVtkPnts->SetPoint(i, PtmpPntVal); tmpPolyData->Modified(); } } else if (isCCd && nodeCC == 12) { // manipulate Z Coordinates of selected FiberBundle int tmpZmove; bool isZmove = this->GetDataNode()->GetPropertyValue("Zmove",tmpZmove); if (!isZmove) return; vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); vtkPoints* tmpVtkPnts = tmpPolyData->GetPoints(); double PtmpPntVal[3]; for (int i=0; iGetNumberOfPoints(); ++i ) { tmpVtkPnts->GetPoint(i,PtmpPntVal); PtmpPntVal[2] = PtmpPntVal[2] + (double) tmpZmove; //PtmpPntVal[2] = PtmpPntVal[2] + 1; tmpVtkPnts->SetPoint(i, PtmpPntVal); tmpPolyData->Modified(); } } else if (isCCd && nodeCC == 13) { int tmpTubeSides; bool isTubeSides = this->GetDataNode()->GetPropertyValue("TubeSides",tmpTubeSides); float tmpRadius; bool isRadius = this->GetDataNode()->GetPropertyValue("TubeRadius",tmpRadius); if (!isTubeSides) return; vtkPolyData *tmpPolyData = m_VtkFiberDataMapperGL->GetInput(); - m_tubes = vtkTubeFilter::New(); + m_tubes->SetInput(tmpPolyData); m_tubes->SidesShareVerticesOn(); m_tubes->SetRadius((double)(tmpRadius)); m_tubes->SetNumberOfSides(tmpTubeSides); m_tubes->Modified(); // m_tubes->Update(); m_vtkTubeMapper->SetInputConnection(m_tubes->GetOutputPort()); m_vtkTubeMapper->ScalarVisibilityOn(); m_vtkTubeMapper->SetScalarModeToUsePointFieldData(); m_vtkTubeMapper->SelectColorArray(""); m_vtkTubeMapper->SelectColorArray("ColorValues"); m_TubeActor->SetMapper(m_vtkTubeMapper); m_TubeActor->GetProperty()->SetOpacity(1); m_TubeActor->GetProperty()->BackfaceCullingOn(); m_FiberAssembly->AddPart(m_TubeActor); m_FiberAssembly->Modified(); } else if (isCCd && nodeCC == 14) { float temprgb[3]; this->GetDataNode()->GetColor( temprgb, NULL ); double trgb[3] = { (double) temprgb[0], (double) temprgb[1], (double) temprgb[2] }; m_TubeActor->GetProperty()->SetColor(trgb); if(m_vtkTubeMapper->GetScalarVisibility()) //can be 0 or 1, for scalarVis On or Off { m_vtkTubeMapper->ScalarVisibilityOff(); } } else if (isCCd && nodeCC == 15) { m_TubeActor->GetProperty()->SetOpacity(0); m_FiberAssembly->RemovePart(m_TubeActor); m_FiberAssembly->Modified(); }else if (isCCd && nodeCC == 16) { float tmpTubeOpacity; bool isTubeOpacity = this->GetDataNode()->GetPropertyValue("TubeOpacity",tmpTubeOpacity); m_TubeActor->GetProperty()->SetOpacity((double) tmpTubeOpacity); m_TubeActor->Modified(); } else if (isCCd && nodeCC == 17) { m_FiberActor->GetProperty()->SetOpacity(0); m_FiberAssembly->RemovePart(m_FiberActor); m_FiberAssembly->Modified(); }else if (isCCd && nodeCC == 18) { m_FiberActor->GetProperty()->SetOpacity(0); m_FiberAssembly->AddPart(m_FiberActor); m_FiberAssembly->Modified(); } //MITK_INFO << m_VtkFiberDataMapperGL->GetArrayName(); /* int displayIndex(0); this->GetDataNode()->GetIntProperty( "DisplayChannel", displayIndex, renderer ); InputImageType *input = const_cast< InputImageType* >( this->GetInput() ); mitk::DiffusionImage *input2 = dynamic_cast< mitk::DiffusionImage* >( input ); input2->SetDisplayIndexForRendering(displayIndex); Superclass::GenerateDataForRenderer(renderer); */ } //template void mitk::FiberBundleMapper3D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { // MITK_INFO << "FiberBundleMapper3D SetDefault Properties(...)"; node->AddProperty( "DisplayChannel", mitk::IntProperty::New( true ), renderer, overwrite ); node->AddProperty( "LineWidth", mitk::IntProperty::New( true ), renderer, overwrite ); node->AddProperty( "ColorCoding", mitk::IntProperty::New( 0 ), renderer, overwrite); node->AddProperty( "VertexOpacity_1", mitk::BoolProperty::New( false ), renderer, overwrite); node->AddProperty( "Set_FA_VertexAlpha", mitk::BoolProperty::New( false ), renderer, overwrite); node->AddProperty( "pointSize", mitk::FloatProperty::New(0.5), renderer, overwrite); node->AddProperty( "setShading", mitk::IntProperty::New(1), renderer, overwrite); node->AddProperty( "Xmove", mitk::IntProperty::New( 0 ), renderer, overwrite); node->AddProperty( "Ymove", mitk::IntProperty::New( 0 ), renderer, overwrite); node->AddProperty( "Zmove", mitk::IntProperty::New( 0 ), renderer, overwrite); node->AddProperty( "RepPoints", mitk::BoolProperty::New( false ), renderer, overwrite); node->AddProperty( "TubeSides", mitk::IntProperty::New( 8 ), renderer, overwrite); node->AddProperty( "TubeRadius", mitk::FloatProperty::New( 0.15 ), renderer, overwrite); node->AddProperty( "TubeOpacity", mitk::FloatProperty::New( 1.0 ), renderer, overwrite); node->AddProperty( "pickable", mitk::BoolProperty::New( true ), renderer, overwrite); Superclass::SetDefaultProperties(node, renderer, overwrite); } vtkProp* mitk::FiberBundleMapper3D::GetVtkProp(mitk::BaseRenderer *renderer) { //MITK_INFO << "FiberBundleMapper3D GetVtkProp(renderer)"; return m_FiberAssembly; } void mitk::FiberBundleMapper3D::ApplyProperties(mitk::BaseRenderer* renderer) { // MITK_INFO << "FiberBundleMapper3D ApplyProperties(renderer)"; } void mitk::FiberBundleMapper3D::UpdateVtkObjects() { // MITK_INFO << "FiberBundleMapper3D UpdateVtkObjects()"; } void mitk::FiberBundleMapper3D::SetVtkMapperImmediateModeRendering(vtkMapper *) { } diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.h b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.h index 07cd89400f..5234d71650 100644 --- a/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.h +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleMapper3D.h @@ -1,103 +1,92 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 17179 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef FiberBundleMapper3D_H_HEADER_INCLUDED #define FiberBundleMapper3D_H_HEADER_INCLUDED //#include "mitkCommon.h" //#include "mitkBaseRenderer.h" -#include "mitkFiberBundle.h" +#include #include -#include "mitkVtkMapper3D.h" -#include "MitkDiffusionImagingExports.h" -//#include "mitkBaseData.h" -#include "vtkAppendPolyData.h" -#include "vtkOpenGLPolyDataMapper.h" -#include "vtkOpenGLActor.h" -#include "vtkPropAssembly.h" -#include "vtkProperty.h" -#include "vtkUnsignedCharArray.h" -#include "vtkTubeFilter.h" +#include + + +#include +#include +#include +#include +#include namespace mitk { //##Documentation //## @brief Mapper for FiberBundles //## @ingroup Mapper // template class MitkDiffusionImaging_EXPORT FiberBundleMapper3D : public VtkMapper3D { public: mitkClassMacro(FiberBundleMapper3D, VtkMapper3D); itkNewMacro(Self); const mitk::FiberBundle* GetInput(); virtual vtkProp *GetVtkProp(mitk::BaseRenderer *renderer); //looks like depricated.. should be replaced bz GetViewProp() static void SetDefaultProperties(DataNode* node, BaseRenderer* renderer = NULL, bool overwrite = false ); virtual void ApplyProperties(mitk::BaseRenderer* renderer); static void SetVtkMapperImmediateModeRendering(vtkMapper *mapper); virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); virtual void GenerateData(); vtkOpenGLPolyDataMapper* getVtkFiberBundleMapper(); protected: FiberBundleMapper3D(); virtual ~FiberBundleMapper3D(); void UpdateVtkObjects(); - vtkAppendPolyData *m_vtkFiberList; - //vtkSmartPointer m_vtkFiberList; - - vtkOpenGLPolyDataMapper *m_VtkFiberDataMapperGL; - //vtkPainterPolyDataMapper *m_VtkFiberDataMapperGL; - //vtkSmartPointer m_VtkFiberDataMapperGL; - - //vtkOpenGLPolyDataMapper *m_VtkFiberDataMapper; - //vtkSmartPointer m_VtkFiberDataMapper; - - vtkOpenGLActor *m_FiberActor; - //vtkSmartPointer m_FiberActor; - vtkTubeFilter *m_tubes; - vtkOpenGLActor *m_TubeActor; - vtkOpenGLPolyDataMapper *m_vtkTubeMapper; + vtkSmartPointer m_VtkFiberDataMapperGL; + vtkSmartPointer m_FiberActor; + vtkSmartPointer m_FiberAssembly; + + vtkSmartPointer m_vtkTubeMapper; + vtkSmartPointer m_tubes; + vtkSmartPointer m_TubeActor; - vtkPropAssembly *m_FiberAssembly; }; } // namespace mitk #endif /* FiberBundleMapper3D_H_HEADER_INCLUDED */