diff --git a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp index 6f347b9e47..393283aeca 100644 --- a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp @@ -1,534 +1,704 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ 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. =========================================================================*/ // Blueberry application and interaction service #include #include // Qmitk #include "QmitkFiberBundleDeveloperView.h" #include +// Qt +#include // MITK -#include //for fiberStructure +//#include //for fiberStructure //===needed when timeSlicedGeometry is null to invoke rendering mechansims ==== #include #include // VTK #include //for randomized FiberStructure #include //for fiberStructure #include //for fiberStructure #include //for geometry //ITK #include + +/*=================================================================================== + * THIS METHOD IMPLEMENTS THE ACTIONS WHICH SHALL BE EXECUTED by the according THREAD + */ +QmitkFiberIDWorker::QmitkFiberIDWorker(QThread* hostingThread, Package4WorkingThread itemPackage) +: m_itemPackage(itemPackage), +m_hostingThread(hostingThread) +{ + +} +void QmitkFiberIDWorker::run() +{ + MITK_INFO << "WmitkFiberIDWORKER....RUN()"; + + itk::TimeProbe clock; + clock.Start(); + + m_itemPackage.st_FBX->DoGenerateFiberIds(); + m_itemPackage.st_idGenerateTimer->stop(); //stop fancy timer + + + clock.Stop(); + m_itemPackage.st_Controls-> + MITK_INFO << "==== Generate idSet ====\n Mean: " << clock.GetMean() << "\n Total: " << clock.GetTotal() ; + // m_hostingThread->quit(); + +} + + + + + + + + +// ========= HERE STARTS THE ACTUAL FIBERBUNDLE DEVELOPER VIEW IMPLEMENTATION ====== + const std::string QmitkFiberBundleDeveloperView::VIEW_ID = "org.mitk.views.fiberbundledeveloper"; const std::string id_DataManager = "org.mitk.views.datamanager"; using namespace berry; QmitkFiberBundleDeveloperView::QmitkFiberBundleDeveloperView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) { + m_hostThread = new QThread; + m_threadInProgress = false; } // Destructor QmitkFiberBundleDeveloperView::~QmitkFiberBundleDeveloperView() { + m_FiberBundleX->Delete(); + delete m_hostThread; + delete m_FiberIDGenerator; + + // m_idGenerateTimer no need to delete, is not initialized using "new" } void QmitkFiberBundleDeveloperView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done in QtDesigner, etc. if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkFiberBundleDeveloperViewControls; m_Controls->setupUi( parent ); - //disabled due to incomplete implementation of these options + /*=========INITIALIZE BUTTON CONFIGURATION ================*/ m_Controls->radioButton_directionX->setEnabled(false); m_Controls->radioButton_directionY->setEnabled(false); m_Controls->radioButton_directionZ->setEnabled(false); - + m_Controls->buttonGenerateFiberIds->setEnabled(false); + m_Controls->buttonGenerateFibers->setEnabled(true); connect( m_Controls->buttonGenerateFibers, SIGNAL(clicked()), this, SLOT(DoGenerateFibers()) ); + connect( m_Controls->buttonGenerateFiberIds, SIGNAL(pressed()), this, SLOT(DoGenerateFiberIDs()) ); + connect( m_Controls->radioButton_directionRandom, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionX, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionY, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionZ, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); + connect( m_Controls->toolBox, SIGNAL(currentChanged ( int ) ), this, SLOT(SelectionChangedToolBox(int)) ); + } // Checkpoint for fiber ORIENTATION if ( m_DirectionRadios.empty() ) { m_DirectionRadios.insert(0, m_Controls->radioButton_directionRandom); m_DirectionRadios.insert(1, m_Controls->radioButton_directionX); m_DirectionRadios.insert(2, m_Controls->radioButton_directionY); m_DirectionRadios.insert(3, m_Controls->radioButton_directionZ); } // set GUI elements of FiberGenerator to according configuration DoUpdateGenerateFibersWidget(); } - +/* THIS METHOD UPDATES ALL GUI ELEMENTS OF QGroupBox DEPENDING ON CURRENTLY SELECTED + * RADIO BUTTONS + */ void QmitkFiberBundleDeveloperView::DoUpdateGenerateFibersWidget() { //get selected radioButton QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // disable radiobuttons if (m_Controls->boxFiberMinLength->isEnabled()) m_Controls->boxFiberMinLength->setEnabled(false); if (m_Controls->labelFiberMinLength->isEnabled()) m_Controls->labelFiberMinLength->setEnabled(false); if (m_Controls->boxFiberMaxLength->isEnabled()) m_Controls->boxFiberMaxLength->setEnabled(false); if (m_Controls->labelFiberMaxLength->isEnabled()) m_Controls->labelFiberMaxLength->setEnabled(false); //enable radiobuttons if (!m_Controls->labelFibersTotal->isEnabled()) m_Controls->labelFibersTotal->setEnabled(true); if (!m_Controls->boxFiberNumbers->isEnabled()) m_Controls->boxFiberNumbers->setEnabled(true); if (!m_Controls->labelDistrRadius->isEnabled()) m_Controls->labelDistrRadius->setEnabled(true); if (!m_Controls->boxDistributionRadius->isEnabled()) m_Controls->boxDistributionRadius->setEnabled(true); } else { // disable radiobuttons if (m_Controls->labelDistrRadius->isEnabled()) m_Controls->labelDistrRadius->setEnabled(false); if (m_Controls->boxDistributionRadius->isEnabled()) m_Controls->boxDistributionRadius->setEnabled(false); //enable radiobuttons if (!m_Controls->labelFibersTotal->isEnabled()) m_Controls->labelFibersTotal->setEnabled(true); if (!m_Controls->boxFiberNumbers->isEnabled()) m_Controls->boxFiberNumbers->setEnabled(true); if (!m_Controls->boxFiberMinLength->isEnabled()) m_Controls->boxFiberMinLength->setEnabled(true); if (!m_Controls->labelFiberMinLength->isEnabled()) m_Controls->labelFiberMinLength->setEnabled(true); if (!m_Controls->boxFiberMaxLength->isEnabled()) m_Controls->boxFiberMaxLength->setEnabled(true); if (!m_Controls->labelFiberMaxLength->isEnabled()) m_Controls->labelFiberMaxLength->setEnabled(true); } } void QmitkFiberBundleDeveloperView::DoGenerateFibers() { // GET SELECTED FIBER DIRECTION QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } - vtkSmartPointer output; // FiberPD stores the generated PolyData + vtkPolyData* output; // FiberPD stores the generated PolyData if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // build polydata with random lines and fibers output = GenerateVtkFibersRandom(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_X ) { // build polydata with XDirection fibers - output = GenerateVtkFibersDirectionX(); + //output = GenerateVtkFibersDirectionX(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_Y ) { // build polydata with YDirection fibers - output = GenerateVtkFibersDirectionY(); + // output = GenerateVtkFibersDirectionY(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_Z ) { // build polydata with ZDirection fibers - output = GenerateVtkFibersDirectionZ(); + // output = GenerateVtkFibersDirectionZ(); } mitk::FiberBundleX::Pointer FB = mitk::FiberBundleX::New(); FB->SetFibers(output); FB->SetGeometry(this->GenerateStandardGeometryForMITK()); mitk::DataNode::Pointer FBNode; FBNode = mitk::DataNode::New(); FBNode->SetName("FiberBundleX"); FBNode->SetData(FB); FBNode->SetVisibility(true); GetDataStorage()->Add(FBNode); + //output->Delete(); const mitk::PlaneGeometry * tsgeo = m_MultiWidget->GetTimeNavigationController()->GetCurrentPlaneGeometry(); if (tsgeo == NULL) { /* GetDataStorage()->Modified etc. have no effect, therefore proceed as followed below */ // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" , mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = GetDataStorage()->ComputeBoundingGeometry3D(rs); // initialize the views to the bounding geometry mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } else { GetDataStorage()->Modified(); //necessary?? m_MultiWidget->RequestUpdate(); //necessary?? } } /* * Generate polydata of random fibers */ -vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersRandom() +vtkPolyData* QmitkFiberBundleDeveloperView::GenerateVtkFibersRandom() { int numOfFibers = m_Controls->boxFiberNumbers->value(); int distrRadius = m_Controls->boxDistributionRadius->value(); int numOfPoints = numOfFibers * distrRadius; std::vector< std::vector > fiberStorage; for (int i=0; i a; fiberStorage.push_back( a ); } //get number of items in fiberStorage MITK_INFO << "Fibers in fiberstorage: " << fiberStorage.size(); /* Generate Point Cloud */ vtkSmartPointer randomPoints = vtkSmartPointer::New(); randomPoints->SetCenter(0.0, 0.0, 0.0); randomPoints->SetNumberOfPoints(numOfPoints); randomPoints->SetRadius(distrRadius); randomPoints->Update(); vtkPoints* pnts = randomPoints->GetOutput()->GetPoints(); /*====== checkpoint: compare initialized and required points =============================*/ if (numOfPoints != pnts->GetNumberOfPoints()) { MITK_INFO << "VTK POINT ERROR, WRONG AMOUNT OF GENRERATED POINTS... COULD BE VTK BUG OR BITFLIP DUE TO COSMIC RADIATION!"; return NULL; }/* ================================= */ /* ASSIGN EACH POINT TO A RANDOM FIBER */ srand((unsigned)time(0)); // init randomizer for (int i=0; iGetNumberOfPoints(); ++i) { //generate random number between 0 and numOfFibers-1 int random_integer; random_integer = (rand()%numOfFibers); //add current point to random fiber fiberStorage.at(random_integer).push_back(i); -// MITK_INFO << "point" << i << " |" << pnts->GetPoint(random_integer)[0] << "|" << pnts->GetPoint(random_integer)[1]<< "|" << pnts->GetPoint(random_integer)[2] << "| into fiber" << random_integer; + // MITK_INFO << "point" << i << " |" << pnts->GetPoint(random_integer)[0] << "|" << pnts->GetPoint(random_integer)[1]<< "|" << pnts->GetPoint(random_integer)[2] << "| into fiber" << random_integer; } //=====timer measurement==== itk::TimeProbe clock; clock.Start(); //========================== - + /* GENERATE VTK POLYLINES OUT OF FIBERSTORAGE */ vtkSmartPointer linesCell = vtkSmartPointer::New(); // Host vtkPolyLines linesCell->Allocate(pnts->GetNumberOfPoints()*2); //allocate for each cellindex also space for the pointId, e.g. [idx | pntID] for (unsigned long i=0; i singleFiber = fiberStorage.at(i); vtkSmartPointer fiber = vtkSmartPointer::New(); fiber->GetPointIds()->SetNumberOfIds((int)singleFiber.size()); for (unsigned long si=0; siGetPointIds()->SetId( si, singleFiber.at(si) ); } linesCell->InsertNextCell(fiber); } /* =======checkpoint for cellarray allocation ==========*/ if ( (linesCell->GetSize()/pnts->GetNumberOfPoints()) != 2 ) { MITK_INFO << "RANDOM FIBER ALLOCATION CAN NOT BE TRUSTED ANYMORE! Correct leak or remove command: linesCell->Allocate(pnts->GetNumberOfPoints()*2) but be aware of possible loss in performance."; }/* ====================================================*/ // MITK_INFO << "CellSize: " << linesCell->GetSize() << " NumberOfCells: " << linesCell->GetNumberOfCells(); /* HOSTING POLYDATA FOR RANDOM FIBERSTRUCTURE */ - vtkSmartPointer PDRandom = vtkSmartPointer::New(); + vtkPolyData* PDRandom = vtkPolyData::New(); PDRandom->SetPoints(pnts); PDRandom->SetLines(linesCell); //====timer measurement======== clock.Stop(); MITK_INFO << "=====Assambling random Fibers to Polydata======\nMean: " << clock.GetMean() << std::endl; MITK_INFO << "Total: " << clock.GetTotal() << std::endl; //============================= return PDRandom; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionX() { int numOfFibers = m_Controls->boxFiberNumbers->value(); vtkSmartPointer linesCell = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); //insert Origin point, this point has index 0 in point array double originX = 0.0; double originY = 0.0; double originZ = 0.0; //after each iteration the origin of the new fiber increases //here you set which direction is affected. double increaseX = 0.0; double increaseY = 1.0; double increaseZ = 0.0; //walk along X axis //length of fibers increases in each iteration for (int i=0; i newFiber = vtkSmartPointer::New(); newFiber->GetPointIds()->SetNumberOfIds(i+2); //create starting point and add it to pointset points->InsertNextPoint(originX + (double)i * increaseX , originY + (double)i * increaseY, originZ + (double)i * increaseZ); //add starting point to fiber newFiber->GetPointIds()->SetId(0,points->GetNumberOfPoints()-1); //insert remaining points for fiber for (int pj=0; pj<=i ; ++pj) { //generate next point on X axis points->InsertNextPoint( originX + (double)pj+1 , originY + (double)i * increaseY, originZ + (double)i * increaseZ ); newFiber->GetPointIds()->SetId(pj+1,points->GetNumberOfPoints()-1); } linesCell->InsertNextCell(newFiber); } vtkSmartPointer PDX = vtkSmartPointer::New(); PDX->SetPoints(points); PDX->SetLines(linesCell); return PDX; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionY() { vtkSmartPointer PDY = vtkSmartPointer::New(); //todo return PDY; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionZ() { vtkSmartPointer PDZ = vtkSmartPointer::New(); //todo return PDZ; } -/* === THIS METHOD GENERATES ESSENTIAL GEOMETRY PARAMETERS FOR THE MITK FRAMEWORK === +/* === OutSourcedMethod: THIS METHOD GENERATES ESSENTIAL GEOMETRY PARAMETERS FOR THE MITK FRAMEWORK === * WITHOUT, the rendering mechanism will ignore objects without valid Geometry * for each object, MITK requires: ORIGIN, SPACING, TRANSFORM MATRIX, BOUNDING-BOX */ mitk::Geometry3D::Pointer QmitkFiberBundleDeveloperView::GenerateStandardGeometryForMITK() { mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // generate origin mitk::Point3D origin; origin[0] = 0; origin[1] = 0; origin[2] = 0; geometry->SetOrigin(origin); // generate spacing float spacing[3] = {1,1,1}; geometry->SetSpacing(spacing); // generate identity transform-matrix vtkMatrix4x4* m = vtkMatrix4x4::New(); geometry->SetIndexToWorldTransformByVtkMatrix(m); // generate boundingbox // for an usable bounding-box use gui parameters to estimate the boundingbox float bounds[] = {500, 500, 500, -500, -500, -500}; // GET SELECTED FIBER DIRECTION QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // use information about distribution parameter to calculate bounding box int distrRadius = m_Controls->boxDistributionRadius->value(); bounds[0] = distrRadius; bounds[1] = distrRadius; bounds[2] = distrRadius; bounds[3] = -distrRadius; bounds[4] = -distrRadius; bounds[5] = -distrRadius; } else { // so far only X,Y,Z directions are available MITK_INFO << "_______GEOMETRY ISSUE_____\n***BoundingBox for X, Y, Z fiber directions are not optimized yet!***"; int maxFibLength = m_Controls->boxFiberMaxLength->value(); bounds[0] = maxFibLength; bounds[1] = maxFibLength; bounds[2] = maxFibLength; bounds[3] = -maxFibLength; bounds[4] = -maxFibLength; bounds[5] = -maxFibLength; } geometry->SetFloatBounds(bounds); geometry->SetImageGeometry(true); //?? return geometry; } +void QmitkFiberBundleDeveloperView::UpdateFiberIDTimer() +{ + //MAKE SURE by yourself THAT NOTHING ELSE THAN A NUMBER IS SET IN THAT LABEL + QString crntValue = m_Controls->infoTimerGenerateFiberIds->text(); + int tmpVal = crntValue.toInt(); + m_Controls->infoTimerGenerateFiberIds->setText(QString::number(++tmpVal)); + m_Controls->infoTimerGenerateFiberIds->update(); + +} + +/* Initialie ID dataset in FiberBundleX */ +void QmitkFiberBundleDeveloperView::DoGenerateFiberIDs() +{ + + struct Package4WorkingThread FiberIdPackage; + FiberIdPackage.st_FBX = m_FiberBundleX; + FiberIdPackage.st_idGenerateTimer = &m_idGenerateTimer; + FiberIdPackage.st_Controls = m_Controls; + + /* ===== TIMER CONFIGURATIONS for visual effect ====== + * start and stop is called in Thread pre- and postprocessing methods */ + m_idGenerateTimer.setInterval( 10 ); + connect( &m_idGenerateTimer, SIGNAL(timeout()), this, SLOT(UpdateFiberIDTimer()) ); + + // THREAD CONFIGURATION + m_FiberIDGenerator = new QmitkFiberIDWorker(m_hostThread, FiberIdPackage); + m_FiberIDGenerator->moveToThread(m_hostThread); + connect(m_hostThread, SIGNAL(started()), this, SLOT( BeforeThread_IdGenerate()) ); + connect(m_hostThread, SIGNAL(started()), m_FiberIDGenerator, SLOT(run())); + connect(m_hostThread, SIGNAL(finished()), this, SLOT(AfterThread_IdGenerate())); + connect(m_hostThread, SIGNAL(terminated()), this, SLOT(AfterThread_IdGenerate())); + m_hostThread->start(QThread::LowestPriority); + + + + // m_Controls->infoTimerGenerateFiberIds->setText(QString::number(clock.GetTotal())); + +} + +void QmitkFiberBundleDeveloperView::BeforeThread_IdGenerate() +{ + m_Controls->infoTimerGenerateFiberIds->setText(QString::number(0)); //set GUI representation of timer to 0 + m_threadInProgress = true; + m_idGenerateTimer.start(); + +} + +void QmitkFiberBundleDeveloperView::AfterThread_IdGenerate() +{ + // m_idGenerateTimer.stop(); //not smart to set timer.stop here, cuz this will override the actual measurements of ITK:PROBE in GUI + m_threadInProgress = false; + + +} + +void QmitkFiberBundleDeveloperView::ResetFiberInfoWidget() +{ + if (m_Controls->infoAnalyseNumOfFibers->isEnabled()) { + m_Controls->infoAnalyseNumOfFibers->setText("-"); + m_Controls->infoAnalyseNumOfPoints->setText("-"); + m_Controls->infoAnalyseNumOfFibers->setEnabled(false); + } +} + +void QmitkFiberBundleDeveloperView::FeedFiberInfoWidget() +{ + if (!m_Controls->infoAnalyseNumOfFibers->isEnabled()) + m_Controls->infoAnalyseNumOfFibers->setEnabled(true); + + QString numOfFibers; + numOfFibers.setNum( m_FiberBundleX->GetFibers()->GetNumberOfLines() ); + QString numOfPoints; + numOfPoints.setNum( m_FiberBundleX->GetFibers()->GetNumberOfPoints() ); + + m_Controls->infoAnalyseNumOfFibers->setText( numOfFibers ); + m_Controls->infoAnalyseNumOfPoints->setText( numOfPoints ); +} + +void QmitkFiberBundleDeveloperView::SelectionChangedToolBox(int idx) +{ + MITK_INFO << "printtoolbox: " << idx; + if (m_Controls->page_FiberInfo->isVisible() && m_FiberBundleX != NULL) + { + FeedFiberInfoWidget(); + + } else { + //if infolables are disabled: return + //else set info back to - and set label and info to disabled + + if (!m_Controls->page_FiberInfo->isVisible()) { + return; + } else { + ResetFiberInfoWidget(); + } + } + +} + +void QmitkFiberBundleDeveloperView::FBXDependendGUIElementsConfigurator(bool isVisible) +{ + // ==== FIBER PROCESSING ELEMENTS ====== + m_Controls->buttonGenerateFiberIds->setEnabled(isVisible); + + +} + + void QmitkFiberBundleDeveloperView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkFiberBundleDeveloperView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } /* OnSelectionChanged is registered to SelectionService, therefore no need to implement SelectionService Listener explicitly */ - void QmitkFiberBundleDeveloperView::OnSelectionChanged( std::vector nodes ) { - for( std::vector::iterator it = nodes.begin(); - it != nodes.end(); ++it ) + /* ==== reset everyhing related to FiberBundleX ====== + * - variable m_FiberBundleX + * - visualization of analysed fiberbundle + */ + m_FiberBundleX = NULL; //reset pointer, so that member does not point to depricated locations + ResetFiberInfoWidget(); + FBXDependendGUIElementsConfigurator(false); + m_Controls->infoTimerGenerateFiberIds->setText("-"); //set GUI representation of timer to - + //==================================================== + + + if (nodes.empty()) + return; + + + for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) { - //flags needed for algorithm execution logic - mitk::DataNode::Pointer node = *it; + + /* CHECKPOINT: FIBERBUNDLE*/ if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { - MITK_INFO << node->GetData()->GetNameOfClass(); + m_FiberBundleX = dynamic_cast(node->GetData()); + if (m_FiberBundleX == NULL) + MITK_INFO << "========ATTENTION=========\n unable to load selected FiberBundleX to FiberBundleDeveloper-plugin \n"; - MITK_INFO << "FBX"; - mitk::FiberBundleX::Pointer serwas = dynamic_cast(node->GetData()); - if (serwas.GetPointer() != NULL){ - vtkSmartPointer pdfb = serwas->GetFibers(); - - MITK_INFO << pdfb->GetNumberOfLines(); - MITK_INFO << pdfb->GetNumberOfPoints(); - }else{ - MITK_INFO << "what happend in datastorage?"; - MITK_INFO << node->GetData()->GetNameOfClass(); - } + // ==== FIBERBUNDLE_INFO ELEMENTS ==== + if ( m_Controls->page_FiberInfo->isVisible() ) + FeedFiberInfoWidget(); - } else { - MITK_INFO << node->GetData()->GetNameOfClass(); + // enable FiberBundleX related Gui Elements, such as buttons etc. + FBXDependendGUIElementsConfigurator(true); + } + + + } - } - void QmitkFiberBundleDeveloperView::Activated() { MITK_INFO << "FB DevelopersV ACTIVATED()"; } diff --git a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.h b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.h index 158258cbb2..9dd8ab3826 100644 --- a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.h +++ b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.h @@ -1,117 +1,184 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ 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 QmitkFiberBundleDeveloperView_h #define QmitkFiberBundleDeveloperView_h #include #include #include #include "ui_QmitkFiberBundleDeveloperViewControls.h" #include #include // Qt #include #include #include // VTK #include #include +#include +#include +#include +#include +/* ==== THIS STRUCT CONTAINS ALL NECESSARY VARIABLES + * TO EXECUTE AND UPDATE GUI ELEMENTS DURING PROCESSING OF A THREAD + */ +struct Package4WorkingThread +{ + mitk::FiberBundleX* st_FBX; + QTimer* st_idGenerateTimer; + Ui::QmitkFiberBundleDeveloperViewControls* st_Controls; +}; + + +// ==================================================================== +// ============= WORKER WHICH IS PASSED TO THREAD ===================== +// ==================================================================== +class QmitkFiberIDWorker : public QObject +{ + Q_OBJECT + +public: + + QmitkFiberIDWorker( QThread*, Package4WorkingThread ); + + public slots: + + void run(); + +private: + //mitk::FiberBundleX* m_FBX; + + Package4WorkingThread m_itemPackage; + QThread* m_hostingThread; + + +}; + + + + + +// ========= HERE STARTS THE ACTUAL FIBERBUNDLE DEVELOPER VIEW ======= + const QString FIB_RADIOBUTTON_DIRECTION_RANDOM = "radioButton_directionRandom"; const QString FIB_RADIOBUTTON_DIRECTION_X = "radioButton_directionX"; const QString FIB_RADIOBUTTON_DIRECTION_Y = "radioButton_directionY"; const QString FIB_RADIOBUTTON_DIRECTION_Z = "radioButton_directionZ"; /*! \brief QmitkFiberBundleView \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup Functionalities */ class QmitkFiberBundleDeveloperView : public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkFiberBundleDeveloperView(); virtual ~QmitkFiberBundleDeveloperView(); virtual void CreateQtPartControl(QWidget *parent); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); virtual void Activated(); protected slots: void DoGenerateFibers(); + void DoGenerateFiberIDs(); void DoUpdateGenerateFibersWidget(); + void UpdateFiberIDTimer(); + void SelectionChangedToolBox(int); + + //SLOTS FOR THREADS + void BeforeThread_IdGenerate(); + void AfterThread_IdGenerate(); + protected: /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged( std::vector nodes ); Ui::QmitkFiberBundleDeveloperViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; private: /* METHODS GENERATING FIBERSTRUCTURES */ - vtkSmartPointer GenerateVtkFibersRandom(); + vtkPolyData* GenerateVtkFibersRandom(); vtkSmartPointer GenerateVtkFibersDirectionX(); vtkSmartPointer GenerateVtkFibersDirectionY(); vtkSmartPointer GenerateVtkFibersDirectionZ(); - /* MITK RELEVANT HELPERMETHODS */ + /* METHODS FOR FIBER PROCESSING OR PREPROCESSING */ + + + /* HELPERMETHODS */ mitk::Geometry3D::Pointer GenerateStandardGeometryForMITK(); + void ResetFiberInfoWidget(); + void FeedFiberInfoWidget(); + void FBXDependendGUIElementsConfigurator(bool); //contains the selected FiberBundle - mitk::DataNode::Pointer m_FiberBundleNode; + mitk::FiberBundleX* m_FiberBundleX; // radiobutton groups QVector< QRadioButton* > m_DirectionRadios; QVector< QRadioButton* > m_FARadios; QVector< QRadioButton* > m_GARadios; + + // timer for updating fiber id generation + QTimer m_idGenerateTimer; + + QmitkFiberIDWorker * m_FiberIDGenerator; + QThread * m_hostThread; + bool m_threadInProgress; + }; #endif // _QMITKFIBERTRACKINGVIEW_H_INCLUDED diff --git a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperViewControls.ui b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperViewControls.ui index 8e9abb471a..1e3f883b98 100644 --- a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperViewControls.ui +++ b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperViewControls.ui @@ -1,660 +1,793 @@ QmitkFiberBundleDeveloperViewControls 0 0 382 691 Form 12 50 false - 0 + 1 - + 0 0 355 395 Fiber Generator 0 Fiber Bundles Generate Fiberbundle Fiber Parameters 11 Total number of Fibers 10 999999999 100 Qt::Horizontal 40 20 11 Distribution Radius 10 99 11 Fiber Length Max (points) 10 50 11 Fiber Length Min (points) 10 10 labelFibersTotal boxFiberNumbers horizontalSpacer_3 labelDistrRadius boxDistributionRadius labelFiberMaxLength boxFiberMaxLength labelFiberMinLength boxFiberMinLength 11 Fiber Orientation along Z Axis along X Axis random true along Y Axis Qt::Horizontal 40 20 Qt::Vertical 20 40 DWI Values GA Values no values true nothing yet implemented 11 FA Values const value false 10 1.000000000000000 0.100000000000000 1.000000000000000 random range false 10 1.000000000000000 0.100000000000000 no values true false 10 1.000000000000000 0.100000000000000 Qt::Vertical 20 40 Page Select a FiberBundle in Datamanager Qt::Vertical 20 40 - + 0 0 343 403 Fiber Processor - + 2 Colors Fiber Coloring Color Fibers Qt::Vertical 20 40 Shape Qt::Vertical 20 40 Fiber Smoothing Smooth Fibers QFrame::StyledPanel QFrame::Raised static value relative in% false 10 none true false 10 9999 Qt::Horizontal 40 20 vtkFilters Tubes vtkDecimatePro vtkSmoothPolyDataFilter Cutting + + + + + Step1: Generate Fibers IDs in FBX + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + QFormLayout::FieldsStayAtSizeHint + + + + + + 10 + + + + Timer: + + + + + + + + 10 + + + + - + + + + + + + + + + Execute Step1 + + + + + + + + 0 + 0 + 185 + 116 + + + + FiberInfo + + + + + + General Information + + + + + + Number of Fibers: + + + + + + + - + + + + + + + Number of Points: + + + + + + + - + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + Qt::Vertical 20 40 diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp index 40fec9e9b6..2d9eefa7d7 100644 --- a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp @@ -1,283 +1,308 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ 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 "mitkFiberBundleX.h" /* musthave */ #include // without geometry, fibers are not rendered #include #include #include #include - +#include // baptize array names const char* mitk::FiberBundleX::COLORCODING_ORIENTATION_BASED = "Color_Orient"; const char* mitk::FiberBundleX::COLORCODING_FA_BASED = "Color_FA"; +const char* mitk::FiberBundleX::FIBER_ID_ARRAY = "Fiber_IDs"; mitk::FiberBundleX::FiberBundleX() { /* ====== GEOMETRY IS ESSENTIAL ======= * by default set a standard geometry, usually geometry is * set by the user on initializing a mitkFiberBundle Object */ // mitk::Geometry3D::Pointer fbgeometry = mitk::Geometry3D::New(); // fbgeometry->SetIdentity(); // this->SetGeometry(fbgeometry); /* ==================================== */ } mitk::FiberBundleX::~FiberBundleX() { - + // Memory Management + m_FiberStructureData->Delete(); } /* === main input method ==== * set computed fibers from tractography algorithms */ -void mitk::FiberBundleX::SetFibers(vtkSmartPointer fiberPD) +void mitk::FiberBundleX::SetFibers(vtkPolyData* fiberPD) { - if (fiberPD.GetPointer() == NULL){ + if (fiberPD == NULL){ MITK_INFO << "passed FiberBundleX is NULL, exit!"; return; } m_FiberStructureData = fiberPD; } /* === main output method === * return fiberbundle as vtkPolyData * Depending on processing of input fibers, this method returns * the latest processed fibers. */ - vtkSmartPointer mitk::FiberBundleX::GetFibers() + vtkPolyData* mitk::FiberBundleX::GetFibers() { return m_FiberStructureData; } /*============================================== *++++ PROCESSING WITH FIBER INFORMATION +++++++ =============================================*/ void mitk::FiberBundleX::DoColorCodingOrientationbased() { //===== FOR WRITING A TEST ======================== // colorT size == tupelComponents * tupelElements // compare color results // to cover this code 100% also polydata needed, where colorarray already exists // + one fiber with exactly 1 point // + one fiber with 0 points //================================================= /* make sure that processing colorcoding is only called when necessary */ if ( m_FiberStructureData->GetPointData()->HasArray(COLORCODING_ORIENTATION_BASED) && m_FiberStructureData->GetNumberOfPoints() == m_FiberStructureData->GetPointData()->GetArray(COLORCODING_ORIENTATION_BASED)->GetNumberOfTuples() ) { // fiberstructure is already colorcoded MITK_INFO << " NO NEED TO REGENERATE COLORCODING!"; return; } /* Finally, execute color calculation */ vtkPoints* extrPoints = m_FiberStructureData->GetPoints(); int numOfPoints = extrPoints->GetNumberOfPoints(); //colors and alpha value for each single point, RGBA = 4 components unsigned char rgba[4] = {0,0,0,0}; int componentSize = sizeof(rgba); vtkUnsignedCharArray *colorsT = vtkUnsignedCharArray::New(); colorsT->Allocate(numOfPoints * componentSize); colorsT->SetNumberOfComponents(componentSize); colorsT->SetName(COLORCODING_ORIENTATION_BASED); /* checkpoint: does polydata contain any fibers */ int numOfFibers = m_FiberStructureData->GetNumberOfLines(); if (numOfFibers < 1) { MITK_INFO << "\n ========= Number of Fibers is below 1 ========= \n"; return; } /* extract single fibers of fiberBundle */ vtkCellArray* fiberList = m_FiberStructureData->GetLines(); for (int fi=0; fiGetNextCell(numOfPoints, idList); /* single fiber checkpoints: is number of points valid */ if (numOfPoints > 1) { /* operate on points of single fiber */ for (int i=0; i 0) { /* The color value of the current point is influenced by the previous point and next point. */ vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]); vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(idList[i+1])[0], extrPoints->GetPoint(idList[i+1])[1], extrPoints->GetPoint(idList[i+1])[2]); vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(idList[i-1])[0], extrPoints->GetPoint(idList[i-1])[1], extrPoints->GetPoint(idList[i-1])[2]); vnl_vector_fixed< double, 3 > diff1; diff1 = currentPntvtk - nextPntvtk; diff1.normalize(); vnl_vector_fixed< double, 3 > diff2; diff2 = currentPntvtk - prevPntvtk; 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 (i==0) { /* First point has no previous point, therefore only diff1 is taken */ vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]); vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(idList[i+1])[0], extrPoints->GetPoint(idList[i+1])[1], extrPoints->GetPoint(idList[i+1])[2]); vnl_vector_fixed< double, 3 > diff1; diff1 = currentPntvtk - nextPntvtk; 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); } else if (i==numOfPoints-1) { /* Last point has no next point, therefore only diff2 is taken */ vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(idList[i])[0], extrPoints->GetPoint(idList[i])[1],extrPoints->GetPoint(idList[i])[2]); vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(idList[i-1])[0], extrPoints->GetPoint(idList[i-1])[1], extrPoints->GetPoint(idList[i-1])[2]); vnl_vector_fixed< double, 3 > diff2; diff2 = currentPntvtk - prevPntvtk; 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); } colorsT->InsertTupleValue(idList[i], rgba); } //end for loop } else if (numOfPoints == 1) { /* a single point does not define a fiber (use vertex mechanisms instead */ continue; // colorsT->InsertTupleValue(0, rgba); } else { MITK_INFO << "Fiber with 0 points detected... please check your tractography algorithm!" ; continue; } }//end for loop m_FiberStructureData->GetPointData()->AddArray(colorsT); //mini test, shall be ported to MITK TESTINGS! if (colorsT->GetSize() != numOfPoints*componentSize) { MITK_INFO << "ALLOCATION ERROR IN INITIATING COLOR ARRAY"; } //===== clean memory ===== colorsT->Delete(); //======================== } +void mitk::FiberBundleX::DoGenerateFiberIds() +{ + if (m_FiberStructureData == NULL) + return; + +// for (int i=0; i<10000000; ++i) +// { +// if(i%500 == 0) +// MITK_INFO << i; +// } + + vtkSmartPointer idFiberFilter = vtkSmartPointer::New(); + idFiberFilter->SetInput(m_FiberStructureData); + idFiberFilter->CellIdsOn(); +// idFiberFilter->PointIdsOn(); // point id's are not needed + idFiberFilter->SetIdsArrayName(FIBER_ID_ARRAY); + idFiberFilter->FieldDataOn(); + idFiberFilter->Update(); + + m_FiberIdDataSet = idFiberFilter->GetOutput(); + +} -double* mitk::FiberBundleX::DoComputeFiberStructureBoundingBox(vtkSmartPointer fiberStructure) +/* COMPUTE BOUND OF FiberBundle */ +double* mitk::FiberBundleX::DoComputeFiberStructureBoundingBox() { - fiberStructure->ComputeBounds(); - double* bounds = fiberStructure->GetBounds(); + m_FiberStructureData->ComputeBounds(); + double* bounds = m_FiberStructureData->GetBounds(); return bounds; } ////private repairMechanism for orientationbased colorcoding //bool mitk::FiberBundleX::doSelfHealingColorOrient(vtkPolyData* healMe) //{ // bool hasHealingSucceeded = false; // MITK_INFO << "FiberBundleX self repair mechanism is called, but not yet implemented"; //// check type of healMe // if (healMe == m_ImportedFiberData) // { // //todo // } // // return hasHealingSucceeded; //} /* ESSENTIAL IMPLEMENTATION OF SUPERCLASS METHODS */ void mitk::FiberBundleX::UpdateOutputInformation() { } void mitk::FiberBundleX::SetRequestedRegionToLargestPossibleRegion() { } bool mitk::FiberBundleX::RequestedRegionIsOutsideOfTheBufferedRegion() { return false; } bool mitk::FiberBundleX::VerifyRequestedRegion() { return true; } void mitk::FiberBundleX::SetRequestedRegion( itk::DataObject *data ) { } \ No newline at end of file diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h index 21a59fe45a..806c62dcba 100644 --- a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h @@ -1,113 +1,121 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision: 11989 $ 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. =========================================================================*/ +/* =============== IMPORTANT TODO =================== + * ==== USE vtkSmartPointer<> when necessary ONLY!!!! + */ #ifndef _MITK_FiberBundleX_H #define _MITK_FiberBundleX_H //includes for MITK datastructure #include "mitkBaseData.h" #include "MitkDiffusionImagingExports.h" //includes storing fiberdata #include //may be replaced by class precompile argument #include // may be replaced by class #include // my be replaced by class - +#include namespace mitk { /** * \brief Base Class for Fiber Bundles; */ class MitkDiffusionImaging_EXPORT FiberBundleX : public BaseData { public: // names of certain arrays (e.g colorcodings, etc.) static const char* COLORCODING_ORIENTATION_BASED; static const char* COLORCODING_FA_BASED; + static const char* FIBER_ID_ARRAY; /* friend classes wanna access typedefs ContainerPointType, ContainerTractType, ContainerType */ friend class FiberBundleXWriter; friend class FiberBundleXReader; // ======virtual methods must have====== virtual void UpdateOutputInformation(); virtual void SetRequestedRegionToLargestPossibleRegion(); virtual bool RequestedRegionIsOutsideOfTheBufferedRegion(); virtual bool VerifyRequestedRegion(); virtual void SetRequestedRegion( itk::DataObject *data ); //======================================= mitkClassMacro( FiberBundleX, BaseData ); itkNewMacro( Self ); /*====FIBERBUNDLE I/O METHODS====*/ - void SetFibers(vtkSmartPointer); //set result of tractography algorithm in vtkPolyData format using vtkPolyLines - vtkSmartPointer GetFibers(); + void SetFibers(vtkPolyData*); //set result of tractography algorithm in vtkPolyData format using vtkPolyLines + vtkPolyData* GetFibers(); vtkSmartPointer GetVertices(); /*===FIBERBUNDLE PROCESSING METHODS====*/ void DoColorCodingOrientationbased(); - + void DoGenerateFiberIds(); /*===FIBERBUNDLE ASSESSMENT METHODS====*/ - // Compute Bounding Box for FiberStructure; needed for MITK Geometry - double* DoComputeFiberStructureBoundingBox(vtkSmartPointer); + // Compute Bounding Box of FiberStructure; needed for MITK Geometry + double* DoComputeFiberStructureBoundingBox(); protected: FiberBundleX(); virtual ~FiberBundleX(); private: //// ====TODO==================================== // bool doSelfHealingColorOrient( vtkPolyData* ); //// ============================================ // The following polydata variables are used for fiber- and pointbased representation of the tractography results. As VTK suggests, one vtkPolyData is used to manage vertices and the other for polylines. // FiberPolyData stores all brain fibers using polylines (in world coordinates) // this variable hosts the smoothed fiber data, this data we generate, therefore a smartpointer structure is recommended // vtkSmartPointer m_FiberPolyData; is depricated // // this variable hosts the original fiber data, no smartpointer needed because who or whatever passes this data to FiberBundleX should use vtkSmartPointer structure - vtkSmartPointer m_FiberStructureData; + vtkPolyData* m_FiberStructureData; //this is a common pointer because fiberDataStructure gets passed to this class. m_FiberStructureData is destroyed in the destructor then. // VertexPolyData stores all original points as vertices computed by tracking algorithms vtkSmartPointer m_VertexPolyData; + // this variable contains all additional IDs of Fibers which are needed for efficient fiber manipulation such as extracting etc. + vtkSmartPointer m_FiberIdDataSet; + + }; } // namespace mitk #endif /* _MITK_FiberBundleX_H */ diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp index 9b2c9fc6c3..002a9aebad 100644 --- a/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp @@ -1,187 +1,187 @@ /*========================================================================= 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 "mitkFiberBundleXMapper3D.h" #include //#include //#include #include #include #include //not essential for mapper #include mitk::FiberBundleXMapper3D::FiberBundleXMapper3D() :m_FiberMapperGLSP(vtkSmartPointer::New()), m_FiberMapperGLWP(vtkOpenGLPolyDataMapper::New()), m_FiberActorSP(vtkSmartPointer::New()), m_FiberActorWP(vtkOpenGLActor::New()), m_FiberAssembly(vtkPropAssembly::New()) { } mitk::FiberBundleXMapper3D::~FiberBundleXMapper3D() { m_FiberAssembly->Delete(); } const mitk::FiberBundleX* mitk::FiberBundleXMapper3D::GetInput() { MITK_INFO << "FiberBundleXxXXMapper3D() GetInput()"; return static_cast ( GetData() ); } /* This method is called once the mapper gets new input, for UI rotation or changes in colorcoding this method is NOT called */ void mitk::FiberBundleXMapper3D::GenerateData() { //MITK_INFO << "GENERATE DATA FOR FBX :)"; //=====timer measurement==== QTime myTimer; myTimer.start(); //========================== // mitk::FiberBundleX::Pointer FBX = dynamic_cast< mitk::FiberBundleX* > (this->GetData()); - mitk::FiberBundleX::Pointer FBX = dynamic_cast (this->GetData()); - if (FBX.GetPointer() == NULL) { - MITK_INFO << "FBX==NULL"; - } - vtkSmartPointer FiberData = FBX->GetFibers(); + mitk::FiberBundleX* FBX = dynamic_cast (this->GetData()); +// if (FBX == NULL) { +// MITK_INFO << "FBX==NULL"; not allowed to be null ;-) +// } + vtkPolyData* FiberData = FBX->GetFibers(); MITK_INFO << "NumOfFibs: " << FiberData->GetNumberOfLines(); MITK_INFO << "NumOfPoints: " << FiberData->GetNumberOfPoints(); m_FiberMapperGLSP->SetInput(FiberData); // m_FiberMapperGLWP->SetInput(FiberData); if ( FiberData->GetPointData()->GetNumberOfArrays() > 0 ) { if ( FiberData->GetPointData()->HasArray(FiberBundleX::COLORCODING_ORIENTATION_BASED) ) { m_FiberMapperGLSP->SelectColorArray(FiberBundleX::COLORCODING_ORIENTATION_BASED); // m_FiberMapperGLWP->SelectColorArray(FiberBundleX::COLORCODING_ORIENTATION_BASED); } else { // iterate through polydata array and take the first best -but valid- array //===ToDo=== //check of componentsize as well, if it is not RGB or RGBA (ie. size 3 or 4), then check if it is a scalar // if scalar then create lookuptable for that. } m_FiberMapperGLSP->ScalarVisibilityOn(); // m_FiberMapperGLWP->ScalarVisibilityOn(); m_FiberMapperGLSP->SetScalarModeToUsePointFieldData(); // m_FiberMapperGLWP->SetScalarModeToUsePointFieldData(); } m_FiberActorSP->SetMapper(m_FiberMapperGLSP); // m_FiberActorWP->SetMapper(m_FiberMapperGLWP); m_FiberActorSP->GetProperty()->SetOpacity(1.0); // m_FiberActorWP->GetProperty()->SetOpacity(1.0); m_FiberAssembly->AddPart(m_FiberActorSP); //====timer measurement======== MITK_INFO << "Execution Time GenerateData() (nmiliseconds): " << myTimer.elapsed(); //============================= } void mitk::FiberBundleXMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) { //MITK_INFO << "FiberBundleXxXXMapper3D()DataForRenderer"; //ToDo do update checks } void mitk::FiberBundleXMapper3D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) { // MITK_INFO << "FiberBundleXxXXMapper3D()SetDefaultProperties"; //MITK_INFO << "FiberBundleMapperX3D 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::FiberBundleXMapper3D::GetVtkProp(mitk::BaseRenderer *renderer) { //MITK_INFO << "FiberBundleXxXXMapper3D()GetVTKProp"; //this->GenerateData(); return m_FiberAssembly; } void mitk::FiberBundleXMapper3D::ApplyProperties(mitk::BaseRenderer* renderer) { // MITK_INFO << "FiberBundleXXXXMapper3D ApplyProperties(renderer)"; } void mitk::FiberBundleXMapper3D::UpdateVtkObjects() { // MITK_INFO << "FiberBundleXxxXMapper3D UpdateVtkObjects()"; } void mitk::FiberBundleXMapper3D::SetVtkMapperImmediateModeRendering(vtkMapper *) { }