18 #include "milxQtRenderWindow.h" 20 #include <vtkRendererCollection.h> 21 #include <vtkPropAssembly.h> 22 #include <vtkCamera.h> 23 #include <vtkCaptionActor2D.h> 24 #include <vtkTextActor.h> 25 #include <vtkTextProperty.h> 26 #include <vtkDistanceRepresentation.h> 27 #include <vtkPolyDataMapper.h> 28 #include <vtkProperty.h> 29 #include <vtkWidgetEventTranslator.h> 30 #include <vtkOrientedGlyphContourRepresentation.h> 31 #include <vtkBoxRepresentation.h> 32 #include <vtkWidgetEvent.h> 33 #include <vtkTransformPolyDataFilter.h> 34 #include <vtkPolyDataNormals.h> 35 #include <vtkCellArray.h> 36 #include <vtkFloatArray.h> 37 #include <vtkPointData.h> 38 #if VTK_MAJOR_VERSION > 5 39 #include <vtkImageMapper3D.h> 42 #include "milxColourMap.h" 52 customScalarBar =
false;
62 renderer = vtkSmartPointer<vtkRenderer>::New();
63 lookupTable = vtkSmartPointer<vtkLookupTable>::New();
64 camera = vtkSmartPointer<vtkCamera>::New();
78 Connector = vtkSmartPointer<vtkEventQtSlotConnect>::New();
95 QVTKWidget::GetRenderWindow()->StereoRenderOff();
96 #if(VTK_MAJOR_VERSION < 6) 97 QVTKWidget::GetRenderWindow()->ReportGraphicErrorsOn();
104 QVTKWidget::GetRenderWindow()->GetInteractor()->SetDesiredUpdateRate(20);
105 QVTKWidget::GetRenderWindow()->GetInteractor()->SetStillUpdateRate(0.01);
110 QVTKWidget::GetRenderWindow()->GetInteractor()->RemoveObservers(vtkCommand::RightButtonPressEvent);
111 QVTKWidget::GetRenderWindow()->GetInteractor()->RemoveObservers(vtkCommand::RightButtonReleaseEvent);
118 vtkCommand::ProgressEvent,
127 lineWidget = vtkSmartPointer<vtkLineWidget2>::New();
135 vtkDistanceRepresentation::SafeDownCast(
distanceWidget->GetRepresentation())->SetLabelFormat(
"%-#6.3g mm");
143 angleWidget = vtkSmartPointer<vtkAngleWidget>::New();
148 planeWidget = vtkSmartPointer<vtkPlaneWidget>::New();
152 boxWidget = vtkSmartPointer<vtkBoxWidget2>::New();
156 vtkSmartPointer<vtkBoxRepresentation> boxRepresentation = vtkSmartPointer<vtkBoxRepresentation>::New();
157 boxWidget->SetRepresentation(boxRepresentation);
160 sphereRep = vtkSmartPointer<vtkSphereRepresentation>::New();
161 sphereRep->SetRepresentationToWireframe();
168 sphereWidget = vtkSmartPointer<vtkSphereWidget2>::New();
174 vtkWidgetEventTranslator *eventTranslator =
sphereWidget->GetEventTranslator();
178 eventTranslator->RemoveTranslation( vtkCommand::MiddleButtonPressEvent );
179 eventTranslator->RemoveTranslation( vtkCommand::MiddleButtonReleaseEvent );
180 eventTranslator->RemoveTranslation( vtkCommand::RightButtonPressEvent );
181 eventTranslator->RemoveTranslation( vtkCommand::RightButtonReleaseEvent );
187 eventTranslator->SetTranslation(vtkCommand::MiddleButtonPressEvent, vtkWidgetEvent::Scale);
188 eventTranslator->SetTranslation(vtkCommand::MiddleButtonReleaseEvent, vtkWidgetEvent::EndScale);
230 vtkSmartPointer<vtkContourRepresentation> rep =
contourWidget->GetContourRepresentation();
234 emit
modelAvailable(rep->GetContourRepresentationAsPolyData(),
"Contour Model");
242 vtkSmartPointer<vtkContourRepresentation> rep =
contourWidget->GetContourRepresentation();
244 vtkSmartPointer<vtkPolyData> nodes = vtkSmartPointer<vtkPolyData>::New();
245 rep->GetNodePolyData(nodes);
257 QSettings settings(
"Shekhar Chandra",
"milxQt");
259 QString exts = openModelExts.c_str();
260 QString path = settings.value(
"recentPath").toString();
262 if(filename.isEmpty())
264 QFileDialog *fileOpener =
new QFileDialog(
this);
265 filename = fileOpener->getOpenFileName(
this,
266 tr(
"Select Model(s) to Open"),
268 tr(exts.toStdString().c_str()) );
272 vtkSmartPointer<vtkPolyData> mesh;
284 axes = vtkSmartPointer<vtkAxesActor>::New();
286 axes->SetTotalLength(xScale, yScale, zScale);
287 axes->GetXAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToViewport();
288 axes->GetYAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToViewport();
289 axes->GetZAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToViewport();
313 orientAxes->GetXAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(0, 0, 0);
314 orientAxes->GetYAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(0, 0, 0);
315 orientAxes->GetZAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(0, 0, 0);
323 renderer->SetBackground2(0.4, 0.5, 0.6);
326 orientAxes->GetXAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(1.0, 1.0, 1.0);
327 orientAxes->GetYAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(1.0, 1.0, 1.0);
328 orientAxes->GetZAxisCaptionActor2D()->GetTextActor()->GetTextProperty()->SetColor(1.0, 1.0, 1.0);
364 printInfo(
"Disabled Two-Sided Lighting.");
372 bool ok, ok1, ok2, ok3;
373 QString newText = QInputDialog::getText(
this, tr(
"Please Enter text"),
374 tr(
"Text:"), QLineEdit::Normal,
"A", &ok);
375 float rValue = QInputDialog::getDouble(
this, tr(
"Please Provide red channel (0.0-1.0)"),
376 tr(
"Red:"), 1.0, -2147483647, 2147483647, 3, &ok1);
377 float gValue = QInputDialog::getDouble(
this, tr(
"Please Provide green channel (0.0-1.0)"),
378 tr(
"Green:"), 0.0, -2147483647, 2147483647, 3, &ok2);
379 float bValue = QInputDialog::getDouble(
this, tr(
"Please Provide blue channel (0.0-1.0)"),
380 tr(
"Blue:"), 0.0, -2147483647, 2147483647, 3, &ok3);
382 if(!ok || !ok1 || !ok2 || !ok3)
385 vtkSmartPointer<vtkTextActor> textActor = vtkSmartPointer<vtkTextActor>::New();
386 textActor->SetInput(newText.toStdString().c_str());
387 textActor->SetTextScaleModeToProp();
388 textActor->GetTextProperty()->SetColor( rValue, gValue, bValue );
391 vtkSmartPointer<vtkTextWidget> textWidget = vtkSmartPointer<vtkTextWidget>::New();
392 textWidget->SetInteractor(QVTKWidget::GetInteractor());
393 textWidget->SetTextActor(textActor);
398 vtkCommand::WidgetActivateEvent,
400 SLOT(
updateTextActor(vtkObject*,
unsigned long,
void*,
void*, vtkCommand*) ));
423 cam->SetFocalPoint(0, 0, 0);
426 cam->SetPosition(0,0,1);
427 cam->SetViewUp(0,-1,0);
431 cam->SetPosition(0,0,-1);
432 cam->SetViewUp(0,1,0);
448 cam->SetFocalPoint(0, 0, 0);
451 cam->SetPosition(0,-1,0);
452 cam->SetViewUp(0,0,1);
456 cam->SetPosition(0,1,0);
457 cam->SetViewUp(0,0,1);
473 cam->SetFocalPoint(0, 0, 0);
474 cam->SetPosition(-1,0,0);
475 cam->SetViewUp(0,0,1);
485 printDebug(
"Changing view to " + QString::number(viewMode));
486 if(viewMode == SAGITTAL)
488 else if(viewMode == CORONAL)
504 void milxQtRenderWindow::saveView(QString filename)
508 if(filename.isEmpty())
510 QSettings settings(
"Shekhar Chandra",
"milxQt");
512 settings.setValue(
"cameraSettings.ClippingRange.x",
renderer->GetActiveCamera()->GetClippingRange()[0]);
513 settings.setValue(
"cameraSettings.ClippingRange.y",
renderer->GetActiveCamera()->GetClippingRange()[1]);
517 settings.setValue(
"cameraSettings.FocalPoint.x",
renderer->GetActiveCamera()->GetFocalPoint()[0]);
518 settings.setValue(
"cameraSettings.FocalPoint.y",
renderer->GetActiveCamera()->GetFocalPoint()[1]);
519 settings.setValue(
"cameraSettings.FocalPoint.z",
renderer->GetActiveCamera()->GetFocalPoint()[2]);
524 settings.setValue(
"cameraSettings.Position.x",
renderer->GetActiveCamera()->GetPosition()[0]);
525 settings.setValue(
"cameraSettings.Position.y",
renderer->GetActiveCamera()->GetPosition()[1]);
526 settings.setValue(
"cameraSettings.Position.z",
renderer->GetActiveCamera()->GetPosition()[2]);
531 settings.setValue(
"cameraSettings.ViewAngle",
renderer->GetActiveCamera()->GetViewAngle());
534 settings.setValue(
"cameraSettings.ViewUp.x",
renderer->GetActiveCamera()->GetViewUp()[0]);
535 settings.setValue(
"cameraSettings.ViewUp.y",
renderer->GetActiveCamera()->GetViewUp()[1]);
536 settings.setValue(
"cameraSettings.ViewUp.z",
renderer->GetActiveCamera()->GetViewUp()[2]);
543 milx::File::SaveCamera(filename.toStdString(),
renderer->GetActiveCamera());
547 void milxQtRenderWindow::saveViewFile()
549 QFileDialog *fileSaver =
new QFileDialog(
this);
550 QSettings settings(
"Shekhar Chandra",
"milxQt");
551 QString path = settings.value(
"recentPath").toString();
553 QString filename = fileSaver->getSaveFileName(
this,
554 tr(
"Select File Name to Save"),
556 tr(
"Camera Files (*.cam *.txt)"));
558 if(filename.isEmpty())
569 file.setFileName(filename);
572 printWarning(
"File provided for loading did not exist. Using internally saved view instead");
576 if(filename.isEmpty())
578 QSettings settings(
"Shekhar Chandra",
"milxQt");
580 double clippingRange[2];
581 clippingRange[0] = settings.value(
"cameraSettings.ClippingRange.x").toDouble();
582 clippingRange[1] = settings.value(
"cameraSettings.ClippingRange.y").toDouble();
584 double focalPoint[3];
585 focalPoint[0] = settings.value(
"cameraSettings.FocalPoint.x").toDouble();
586 focalPoint[1] = settings.value(
"cameraSettings.FocalPoint.y").toDouble();
587 focalPoint[2] = settings.value(
"cameraSettings.FocalPoint.z").toDouble();
590 position[0] = settings.value(
"cameraSettings.Position.x").toDouble();
591 position[1] = settings.value(
"cameraSettings.Position.y").toDouble();
592 position[2] = settings.value(
"cameraSettings.Position.z").toDouble();
594 double angle = settings.value(
"cameraSettings.ViewAngle").toDouble();
597 viewUp[0] = settings.value(
"cameraSettings.ViewUp.x").toDouble();
598 viewUp[1] = settings.value(
"cameraSettings.ViewUp.y").toDouble();
599 viewUp[2] = settings.value(
"cameraSettings.ViewUp.z").toDouble();
601 camera->SetClippingRange(clippingRange);
602 camera->SetFocalPoint(focalPoint);
603 camera->SetPosition(position);
604 camera->SetViewAngle(angle);
605 camera->SetViewUp(viewUp);
609 milx::File::LoadCamera(filename.toStdString(),
camera);
613 QVTKWidget::GetRenderWindow()->Render();
616 void milxQtRenderWindow::loadViewFile()
618 QFileDialog *fileOpener =
new QFileDialog(
this);
619 QSettings settings(
"Shekhar Chandra",
"milxQt");
620 QString path = settings.value(
"recentPath").toString();
622 QString filename = fileOpener->getOpenFileName(
this,
623 tr(
"Select File to Open"),
625 tr(
"Camera Files (*.cam *.txt)") );
627 if(filename.isEmpty())
649 vtkSmartPointer<vtkActor> rndActor = vtkSmartPointer<vtkActor>::New();
650 rndActor->SetMapper(actor->GetMapper());
652 rndActor->SetUserMatrix(transformMatrix);
661 if(imgActor == item.parentActor)
666 imgActor->GetDisplayExtent(extents);
670 item.parentActor = imgActor;
671 item.imageActor = vtkSmartPointer<vtkImageActor>::New();
672 item.imageActor->SetDisplayExtent(extents);
673 #if(VTK_MAJOR_VERSION > 5) 674 item.imageActor->GetMapper()->SetInputData(imgActor->GetInput());
676 item.imageActor->SetInput(imgActor->GetInput());
681 item.imageActor->SetUserMatrix( transformMatrix );
700 vtkSmartPointer<vtkTextWidget> textWidget = vtkTextWidget::SafeDownCast(obj);
701 vtkSmartPointer<vtkTextActor> textActor = textWidget->GetTextActor();
704 msgBox.setText(
"Would you like to remove this text?");
705 msgBox.setInformativeText(
"Remove this text?");
706 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
707 msgBox.setDefaultButton(QMessageBox::No);
708 int ret = msgBox.exec();
710 if(ret == QMessageBox::No)
712 bool ok, ok1, ok2, ok3;
713 QString newText = QInputDialog::getText(
this, tr(
"Please Enter text"),
714 tr(
"Text:"), QLineEdit::Normal, textActor->GetInput(), &ok);
715 float rValue = QInputDialog::getDouble(
this, tr(
"Please Provide red channel (0.0-1.0)"),
716 tr(
"Red:"), 1.0, -2147483647, 2147483647, 3, &ok1);
717 float gValue = QInputDialog::getDouble(
this, tr(
"Please Provide green channel (0.0-1.0)"),
718 tr(
"Green:"), 0.0, -2147483647, 2147483647, 3, &ok2);
719 float bValue = QInputDialog::getDouble(
this, tr(
"Please Provide blue channel (0.0-1.0)"),
720 tr(
"Blue:"), 0.0, -2147483647, 2147483647, 3, &ok3);
722 if(!ok || !ok1 || !ok2 || !ok3)
725 textActor->SetInput(newText.toStdString().c_str());
726 textActor->SetTextScaleModeToProp();
727 textActor->GetTextProperty()->SetColor( rValue, gValue, bValue );
729 textWidget->SetTextActor(textActor);
739 vtkSmartPointer<vtkImageActor> actor = vtkImageActor::SafeDownCast(obj);
744 if(actor == item.parentActor)
748 actor->GetDisplayExtent(extents);
750 item.imageActor->SetDisplayExtent(extents);
751 item.imageActor->SetInterpolate(actor->GetInterpolate());
766 if(actor == item.parentActor)
770 actor->GetDisplayExtent(extents);
772 item.imageActor->SetDisplayExtent(extents);
773 item.imageActor->SetInterpolate(actor->GetInterpolate());
783 void milxQtRenderWindow::userEvent(QMouseEvent *event)
788 void milxQtRenderWindow::userEvent(QKeyEvent *event)
793 void milxQtRenderWindow::userEvent(QWheelEvent *event)
845 if(imgActor == item.imageActor || imgActor == item.parentActor)
847 foundItem.imageActor = item.imageActor;
848 foundItem.parentActor = item.parentActor;
862 if(windowToImportFrom)
867 vtkSmartPointer<vtkMatrix4x4> transformModel = vtkSmartPointer<vtkMatrix4x4>::New();
869 transformModel->Invert();
875 connect(windowToImportFrom, SIGNAL(
modified(vtkSmartPointer<vtkImageActor> )),
this, SLOT(
updateImageActor(vtkSmartPointer<vtkImageActor>)));
879 vtkActorCollection *actors = windowToImportFrom->
GetActors();
881 size_t n = actors->GetNumberOfItems();
883 actors->InitTraversal();
884 for(
size_t j = 0; j < n; j ++)
886 printDebug(
"Adding Generic Actor into scene.");
890 qApp->processEvents();
910 if(minRange == 0.0 && maxRange == 0.0)
919 colours->toRainbow();
920 colours->SetRange(range);
934 if(minRange == 0.0 && maxRange == 0.0)
944 colours->SetRange(range);
958 if(minRange == 0.0 && maxRange == 0.0)
968 colours->SetRange(range);
982 if(minRange == 0.0 && maxRange == 0.0)
992 colours->SetRange(range);
1006 if(minRange == 0.0 && maxRange == 0.0)
1010 range[0] = minRange;
1011 range[1] = maxRange;
1015 colours->toSeismic();
1016 colours->SetRange(range);
1030 if(minRange == 0.0 && maxRange == 0.0)
1034 range[0] = minRange;
1035 range[1] = maxRange;
1039 colours->toLogGray();
1040 colours->SetRange(range);
1054 if(minRange == 0.0 && maxRange == 0.0)
1058 range[0] = minRange;
1059 range[1] = maxRange;
1064 colours->SetRange(range);
1078 if(minRange == 0.0 && maxRange == 0.0)
1082 range[0] = minRange;
1083 range[1] = maxRange;
1087 colours->toNIH_FIRE();
1088 colours->SetRange(range);
1102 if(minRange == 0.0 && maxRange == 0.0)
1106 range[0] = minRange;
1107 range[1] = maxRange;
1112 colours->SetRange(range);
1126 if(minRange == 0.0 && maxRange == 0.0)
1130 range[0] = minRange;
1131 range[1] = maxRange;
1136 colours->SetRange(range);
1150 if(minRange == 0.0 && maxRange == 0.0)
1154 range[0] = minRange;
1155 range[1] = maxRange;
1160 colours->SetRange(range);
1174 if(minRange == 0.0 && maxRange == 0.0)
1178 range[0] = minRange;
1179 range[1] = maxRange;
1184 colours->SetRange(range);
1198 if(minRange == 0.0 && maxRange == 0.0)
1202 range[0] = minRange;
1203 range[1] = maxRange;
1207 colours->toCOOLWARM();
1208 colours->SetRange(range);
1222 if(minRange == 0.0 && maxRange == 0.0)
1226 range[0] = minRange;
1227 range[1] = maxRange;
1232 colours->SetRange(range);
1246 if(minRange == 0.0 && maxRange == 0.0)
1250 range[0] = minRange;
1251 range[1] = maxRange;
1256 colours->SetRange(range);
1270 if(minRange == 0.0 && maxRange == 0.0)
1274 range[0] = minRange;
1275 range[1] = maxRange;
1279 colours->toSpectral();
1280 colours->SetRange(range);
1294 if(minRange == 0.0 && maxRange == 0.0)
1298 range[0] = minRange;
1299 range[1] = maxRange;
1303 colours->toGNUPlot();
1304 colours->SetRange(range);
1318 if(minRange == 0.0 && maxRange == 0.0)
1322 range[0] = minRange;
1323 range[1] = maxRange;
1327 colours->toCubeHelix();
1328 colours->SetRange(range);
1342 if(minRange == 0.0 && maxRange == 0.0)
1346 range[0] = minRange;
1347 range[1] = maxRange;
1352 colours->SetRange(range);
1386 if(QVTKWidget::GetRenderWindow()->GetRenderers()->GetNumberOfItems() == 0 ||
renderer != QVTKWidget::GetRenderWindow()->GetRenderers()->GetFirstRenderer())
1387 QVTKWidget::GetRenderWindow()->AddRenderer(
renderer);
1390 printDebug(
"Size of window: " + QString::number(QVTKWidget::size().height()) +
"x" + QString::number(QVTKWidget::size().width()));
1391 printDebug(
"Actual Size of window: " + QString::number(QVTKWidget::GetRenderWindow()->GetSize()[0]) +
"x" + QString::number(QVTKWidget::GetRenderWindow()->GetSize()[1]));
1392 if(QVTKWidget::size().height() < minWindowSize || QVTKWidget::size().width() < minWindowSize)
1394 QVTKWidget::GetRenderWindow()->SetSize(minWindowSize, minWindowSize);
1398 int *winSize = QVTKWidget::GetRenderWindow()->GetSize();
1399 QVTKWidget::resize(winSize[0], winSize[1]);
1407 void milxQtRenderWindow::createCustomConnections(QList<QAction *> actionsInMenu)
1409 foreach(QAction *action, actionsInMenu)
1411 printDebug(
"Adding action for custom operations.");
1416 void milxQtRenderWindow::createCustomConnections(QMenu *fromMenu)
1418 QList<QAction *> actionsInMenu = fromMenu->actions();
1420 foreach(QAction *action, actionsInMenu)
1422 printDebug(
"Adding action for custom operations.");
1431 if(currentWindow == 0)
1433 printError(
"Error in determining parent of action");
1443 vtkSmartPointer<vtkMatrix4x4> transformModel = vtkSmartPointer<vtkMatrix4x4>::New();
1445 transformModel->Invert();
1451 connect(currentWindow, SIGNAL(
modified(vtkSmartPointer<vtkImageActor> )),
this, SLOT(
updateImageActor(vtkSmartPointer<vtkImageActor>)));
1455 vtkActorCollection *actors = currentWindow->
GetActors();
1457 size_t n = actors->GetNumberOfItems();
1459 actors->InitTraversal();
1460 for(
size_t j = 0; j < n; j ++)
1462 printDebug(
"Adding Generic Actor into scene.");
1466 qApp->processEvents();
1482 menu->addAction(currAct);
1486 menu->addMenu(currMenu);
1518 menu->addSeparator();
1521 menu->addAction(currAct);
1525 menu->addMenu(currMenu);
1534 QFile qtFile(filename);
1535 if(!qtFile.open(QIODevice::ReadOnly))
1537 printError(
"Unable to open model using Qt for reading.");
1541 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
1542 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
1543 vtkSmartPointer<vtkFloatArray> normals = vtkSmartPointer<vtkFloatArray>::New();
1544 normals->SetNumberOfComponents(3);
1546 QTextStream inFile(&qtFile);
1547 while (!inFile.atEnd())
1552 if(lineType ==
"" || lineType ==
"#" || lineType ==
"mtllib" || lineType ==
"usemtl" || lineType ==
"g" || lineType ==
"s" || lineType ==
"vt")
1554 else if(lineType ==
"v")
1557 inFile >> position[0] >> position[1] >> position[2];
1559 points->InsertNextPoint(position);
1561 else if(lineType ==
"vn")
1564 inFile >> normal[0] >> normal[1] >> normal[2];
1566 normals->InsertNextTupleValue(normal);
1568 else if(lineType ==
"f")
1571 inFile >> face[0] >> face[1] >> face[2];
1574 cells->InsertNextCell(3);
1575 for(
size_t j = 0; j < 3; j ++)
1577 QStringList faceParts = face[j].split(
'/');
1579 cells->InsertCellPoint(faceParts[0].toInt()-1);
1585 data = vtkSmartPointer<vtkPolyData>::New();
1586 data->SetPoints(points);
1587 data->SetPolys(cells);
1588 data->GetPointData()->SetNormals(normals);
1596 dataPicker = vtkSmartPointer<vtkPointPicker>::New();
1598 Connector->Connect( QVTKWidget::GetRenderWindow()->GetInteractor(),
1599 vtkCommand::MouseMoveEvent,
1609 vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::SafeDownCast(obj);
1611 QString message =
"";
1617 if (
dataPicker->Pick(iren->GetEventPosition()[0],
1618 iren->GetEventPosition()[1],
1627 vtkIdType nVolIdx =
dataPicker->GetPointId();
1629 message =
"Point " + QString::number(nVolIdx) +
": (" + QString::number(point[0]) +
", " + QString::number(point[1]) +
", " + QString::number(point[2]) +
")";
1639 contextMenu->setTitle(QApplication::translate(
"MainWindow",
"Rendering", 0, QApplication::UnicodeUTF8));
1642 contourAct->setText(QApplication::translate(
"Render",
"Contour Mode", 0, QApplication::UnicodeUTF8));
1646 contourPolyDataAct->setText(QApplication::translate(
"Render",
"Create Model From Contour", 0, QApplication::UnicodeUTF8));
1648 contourNodePolyDataAct->setText(QApplication::translate(
"Render",
"Save Contour", 0, QApplication::UnicodeUTF8));
1650 contourInitAct->setText(QApplication::translate(
"Render",
"Load Contour", 0, QApplication::UnicodeUTF8));
1655 contourMenu->setTitle(QApplication::translate(
"Render",
"Contouring", 0, QApplication::UnicodeUTF8));
1663 backgroundAct->setText(QApplication::translate(
"Render",
"&White Background", 0, QApplication::UnicodeUTF8));
1667 axesAct->setText(QApplication::translate(
"Render",
"&Axes", 0, QApplication::UnicodeUTF8));
1671 lightingAct->setText(QApplication::translate(
"Render",
"&Two-Sided Lighting", 0, QApplication::UnicodeUTF8));
1676 lineAct->setText(QApplication::translate(
"Render",
"&Draw Line", 0, QApplication::UnicodeUTF8));
1681 distanceAct->setText(QApplication::translate(
"Render",
"&Measure Distance", 0, QApplication::UnicodeUTF8));
1686 biDirectionAct->setText(QApplication::translate(
"Render",
"&Measure Cross Distance", 0, QApplication::UnicodeUTF8));
1691 angleAct->setText(QApplication::translate(
"Render",
"&Measure Angle", 0, QApplication::UnicodeUTF8));
1696 planeAct->setText(QApplication::translate(
"Render",
"&Draw Plane", 0, QApplication::UnicodeUTF8));
1700 boxAct =
new QAction(
this);
1701 boxAct->setText(QApplication::translate(
"Render",
"&Draw Box/Cuboid", 0, QApplication::UnicodeUTF8));
1702 boxAct->setCheckable(
true);
1703 boxAct->setChecked(
false);
1706 sphereAct->setText(QApplication::translate(
"Render",
"&Draw Sphere/Circle", 0, QApplication::UnicodeUTF8));
1711 humanAct->setText(QApplication::translate(
"Render",
"Show Human Orientation", 0, QApplication::UnicodeUTF8));
1716 textAct->setText(QApplication::translate(
"Render",
"&Insert Text", 0, QApplication::UnicodeUTF8));
1719 crosshairAct->setText(QApplication::translate(
"Render",
"&Crosshair", 0, QApplication::UnicodeUTF8));
1724 windowPropertiesMenu->setTitle(QApplication::translate(
"Render",
"Window Properties", 0, QApplication::UnicodeUTF8));
1740 viewXY =
new QAction(
this);
1741 viewXY->setText(QApplication::translate(
"Render",
"Axial (xy-plane)", 0, QApplication::UnicodeUTF8));
1742 viewXY->setShortcut(tr(
"Alt+a"));
1743 viewXY->setCheckable(
true);
1744 viewXY->setChecked(
true);
1745 viewZX =
new QAction(
this);
1746 viewZX->setText(QApplication::translate(
"Render",
"Coronal (zx-plane)", 0, QApplication::UnicodeUTF8));
1747 viewZX->setShortcut(tr(
"Alt+c"));
1748 viewZX->setCheckable(
true);
1749 viewZY =
new QAction(
this);
1750 viewZY->setText(QApplication::translate(
"Render",
"Sagittal (zy-plane)", 0, QApplication::UnicodeUTF8));
1751 viewZY->setShortcut(tr(
"Alt+s"));
1752 viewZY->setCheckable(
true);
1754 saveViewAct->setText(QApplication::translate(
"Render",
"Save View", 0, QApplication::UnicodeUTF8));
1757 loadViewAct->setText(QApplication::translate(
"Render",
"Load View", 0, QApplication::UnicodeUTF8));
1760 saveViewFileAct->setText(QApplication::translate(
"Render",
"Save View to File", 0, QApplication::UnicodeUTF8));
1763 loadViewFileAct->setText(QApplication::translate(
"Render",
"Load View from File", 0, QApplication::UnicodeUTF8));
1766 scaleAct->setText(QApplication::translate(
"Render",
"&Scalar Bar", 0, QApplication::UnicodeUTF8));
1777 actionDefault->setText(QApplication::translate(
"Render",
"None", 0, QApplication::UnicodeUTF8));
1883 refreshAct->setText(QApplication::translate(
"Render",
"&Refresh", 0, QApplication::UnicodeUTF8));
1886 resetAct->setText(QApplication::translate(
"Render",
"Reset", 0, QApplication::UnicodeUTF8));
1887 resetAct->setIcon(QIcon(
":/resources/toolbar/refresh.png"));
1894 connect(
this, SIGNAL(mouseEvent(QMouseEvent*)),
this, SLOT(userEvent(QMouseEvent*)));
1921 connect(
boxAct, SIGNAL(triggered()),
this, SLOT(
refresh()));
1948 connect(
saveViewAct, SIGNAL(triggered()),
this, SLOT(saveView()));
1950 connect(
saveViewFileAct, SIGNAL(triggered()),
this, SLOT(saveViewFile()));
1951 connect(
loadViewFileAct, SIGNAL(triggered()),
this, SLOT(loadViewFile()));
1954 connect(
resetAct, SIGNAL(triggered()),
this, SLOT(
reset()));
1999 event->acceptProposedAction();
2004 if(currentEvent->mimeData()->hasFormat(
"text/uri-list") || currentEvent->mimeData()->hasFormat(
"text/plain"))
2005 currentEvent->acceptProposedAction();
2010 QDrag *drag =
new QDrag(
this);
2011 QMimeData *mimeData =
new QMimeData;
2014 urls.append( QUrl(
"file://localhost/" +
getName()) );
2016 mimeData->setUrls(urls);
2017 drag->setMimeData(mimeData);
2019 drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::CopyAction);
2024 if(currentEvent->source() ==
this)
2029 QList<QUrl> urlsList = currentEvent->mimeData()->urls();
2030 QString tmp, typeString = currentEvent->mimeData()->text();
2032 for(
int j = 0; j < urlsList.size(); j ++)
2034 if(urlsList[j].isValid())
2036 printInfo(
"Dropped Path into Render Window: " + urlsList[j].path());
2044 printError(
"Data type unsupported. Passing on drop... ");
2045 currentEvent->ignore();
2050 currentEvent->acceptProposedAction();
2055 vtkSmartPointer<vtkPolyData> human;
2058 vtkSmartPointer<vtkPolyData> humanTransformed;
2061 vtkSmartPointer<vtkTransform> transf = vtkSmartPointer<vtkTransform>::New();
2062 transf->SetMatrix(mat);
2064 vtkSmartPointer<vtkTransformPolyDataFilter> transformer = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
2065 #if VTK_MAJOR_VERSION <= 5 2066 transformer->SetInput(human);
2068 transformer->SetInputData(human);
2070 transformer->SetTransform(transf);
2071 transformer->Update();
2073 vtkSmartPointer<vtkPolyDataNormals> normalsHuman = vtkSmartPointer<vtkPolyDataNormals>::New();
2074 #if VTK_MAJOR_VERSION <= 5 2075 normalsHuman->SetInput(transformer->GetOutput());
2077 normalsHuman->SetInputData(transformer->GetOutput());
2079 normalsHuman->Update();
2081 humanTransformed = normalsHuman->GetOutput();
2084 humanTransformed = human;
2086 vtkSmartPointer<vtkPropAssembly> propAssembly = vtkSmartPointer<vtkPropAssembly>::New();
2087 orientAxes = vtkSmartPointer<vtkAxesActor>::New();
2091 orientAxes->GetXAxisCaptionActor2D()->GetCaptionTextProperty()->ShadowOff();
2092 orientAxes->GetXAxisCaptionActor2D()->GetCaptionTextProperty()->SetFontSize(14);
2093 orientAxes->GetXAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToNone();
2094 orientAxes->GetYAxisCaptionActor2D()->GetCaptionTextProperty()->ShadowOff();
2095 orientAxes->GetYAxisCaptionActor2D()->GetCaptionTextProperty()->SetFontSize(14);
2096 orientAxes->GetYAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToNone();
2097 orientAxes->GetZAxisCaptionActor2D()->GetCaptionTextProperty()->ShadowOff();
2098 orientAxes->GetZAxisCaptionActor2D()->GetCaptionTextProperty()->SetFontSize(14);
2099 orientAxes->GetZAxisCaptionActor2D()->GetTextActor()->SetTextScaleModeToNone();
2110 vtkSmartPointer<vtkPolyDataMapper> humanMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
2111 #if VTK_MAJOR_VERSION <= 5 2112 humanMapper->SetInput(humanTransformed);
2114 humanMapper->SetInputData(humanTransformed);
2116 vtkSmartPointer<vtkActor> humanActor = vtkSmartPointer<vtkActor>::New();
2117 humanActor->SetMapper(humanMapper);
2118 humanActor->GetProperty()->SetInterpolationToPhong();
2120 humanActor->GetProperty()->SetColor(60/255.0, 232/255.0, 30/255.0);
2121 propAssembly->AddPart(humanActor);
2122 humanGlyph = vtkSmartPointer<vtkOrientationMarkerWidget>::New();
2124 humanGlyph->SetOrientationMarker(propAssembly);
2125 humanGlyph->SetInteractor(QVTKWidget::GetInteractor());
QAction * scaleAct
Action for the scale bar of the display.
void printWarning(QString msg)
Warning message wrapper for console.
virtual void createMenu(QMenu *menu)
Create the menu for the data in this object. Used for context menu and file menus.
void disableAxes()
Disables the axes display.
int defaultView
Default view for data (default is axial)
virtual void colourMapToSpectral(double minRange=0.0, double maxRange=0.0)
Change the colour map to Spectral.
bool logScale
Using custom scalar bar?
vtkSmartPointer< vtkAxesActor > axes
Axes for the model.
void printError(QString msg)
Error message wrapper for console.
void dragEnterEvent(QDragEnterEvent *event)
Part of the Drag and Drop feature members. Tells what drags to accept.
void RemoveActor(vtkSmartPointer< vtkProp > actor)
Remove the VTK actor from this window.
LabelledAction * actionGNUPlot
GNUPlot colours.
virtual void colourMapToVTK(double minRange=0.0, double maxRange=0.0)
Change the colour map to inverse of default VTK.
QAction * saveViewFileAct
Save camera view to file.
LabelledAction * actionHSV
Cube Helix colours.
QMenu * viewMenu
Context Menu.
vtkSmartPointer< vtkBoxWidget2 > boxWidget
Used for measuring angles.
QAction * lightingAct
Action for two-sided lighting of the display.
int currentView
Current view for data.
QActionGroup * windowActionGroup
used for the custom menu
vtkActorCollection * GetActors()
Get all the actors in the render window.
QMenu * colourMapsMenu()
Return the colourmaps menu with the milxQtRenderWindow class ordering. This is for the benefit of der...
void enableAxes(float xScale=1.0, float yScale=1.0, float zScale=1.0)
Enable axes display with each arrow for dimension scaled as provided.
vtkSmartPointer< vtkContourWidget > contourWidget
contour interaction
vtkSmartPointer< vtkRenderer > renderer
Renderer for the data.
void AddActor(vtkSmartPointer< vtkProp > actor)
Add a VTK actor to this window.
QAction * actionNIH_FIRE
NIH_FIRE colours.
This class represents the MILX Qt Render Window Display object using QVTK.
vtkSmartPointer< vtkAngleWidget > angleWidget
Used for measuring angles.
void updateQtEvents()
Update the Qt events, used to keep UI responsive.
virtual QString strippedNamePrefix()
Returns the stripped (path removed) name of the data with "Generic" prefix.
vtkSmartPointer< vtkLookupTable > lookupTable
Lookup table for the shapes/images, base class is used to allow references to different look up table...
virtual void updateTextActor(vtkObject *obj, unsigned long, void *client_data, void *, vtkCommand *command)
Update any text actors in display to current slice.
QAction * viewZY
Change view to zy-plane (Coronal)
QAction * actionNIH
NIH colours.
void createConnections()
Create the connections for context menu etc.
bool loaded
Loaded Image from file?
bool axesBefore
Axes displayed?
QAction * actionLogGray
Logarithmic Gray colours.
vtkSmartPointer< vtkBiDimensionalWidget > biDirectionWidget
Used for measuring cross distances.
vtkSmartPointer< vtkMatrix4x4 > transformMatrix
Transform matrix for actor(s)
QAction * actionKnee
Knee colours.
QMenu * contextMenu
Context Menu.
QAction * axesAct
Action for axes of the display.
virtual vtkDataSet * GetDataSet()
Get the data, Implement in derived class that uses data derived from vtkDataSet, like vtkPolyData or ...
QAction * boxAct
Action for box drawing display.
vtkSmartPointer< vtkOrientationMarkerWidget > humanGlyph
Glyph for showing equivalent view on human.
QAction * crosshairAct
Action for crosshair.
virtual void contour()
Draw contour interactively.
virtual void updateLookupTable()
Implement this into your derived class to ensure the new colourmap is passed on to your viewing data ...
virtual void viewToZXPlane()
Change view to zx-plane.
void modified(vtkSmartPointer< vtkImageActor >)
Emit signal to allow updating of image actors if present.
LabelledAction * actionCubeHelix
Cube Helix colours.
This class represents the MILX Qt Window Display object using QVTK.
virtual void colourMapToBone(double minRange=0.0, double maxRange=0.0)
Change the colour map to Bone.
virtual void colourMapToFS(double minRange=0.0, double maxRange=0.0)
Change the colour map to FS (FreeSurfer)
QAction * humanAct
Show human view orientation glyph?
QAction * actionInvRainbow
Inv Default colours.
QList< QMenu * > menusToAdd
Context Menu's to add.
static bool OpenModel(const std::string filename, vtkSmartPointer< vtkPolyData > &data)
Opens a model file, which can be a VTK XML, Legacy VTK PolyData File (i.e. either a *...
virtual void colourMapToSeismic(double minRange=0.0, double maxRange=0.0)
Change the colour map to Seismic.
QAction * backgroundAct
Action for axes of the display.
LabelledAction * actionSpectral
Spectral colours.
vtkSmartPointer< vtkDistanceWidget > distanceWidget
Used for measuring distances.
vtkSmartPointer< vtkLineWidget2 > lineWidget
Used for drawing lines.
QActionGroup * viewGroup
Grouping for check boxes.
void printDebug(QString msg)
Debug message wrapper for console.
QAction * contourPolyDataAct
Save contour surface points as polydata.
QAction * lineAct
Action for distance measuring display.
void addModelActor(vtkSmartPointer< vtkActor > mdlActor)
Directly add model actor to generic view.
virtual void disableCrosshair()
Restores the mouse pointer to default.
QAction * actionRainbow
Default colours.
QAction * actionDefault
Default colours.
vtkSmartPointer< vtkLookupTable > GetOutput()
Get the colourmap set.
QAction * contourAct
Action for contouring surface points using Dijkstras algorithm.
bool orientationAxes
Display orientation (posterior etc.) axes?
QList< ImageActorItem > imageActors
Images actors being displayed in model view.
void Render()
Force Render or Update of the display.
LabelledAction * actionBone
Spectral colours.
void orientDisplay()
Toggles orientation marker.
void enableUpdates(QStatusBar *bar)
Enables the update of coordinates to the status bar provided directly. Update is done on mouse moveme...
QAction * actionJet
Jet colours.
virtual void colourMapToAAL(double minRange=0.0, double maxRange=0.0)
Change the colour map to AAL.
virtual void colourMapToNIH(double minRange=0.0, double maxRange=0.0)
Change the colour map to NIH.
void contourInitFromPolyData(QString filename="")
Load contour from polydata/model.
int orientationView
view orientation standard
virtual void updateCoords(vtkObject *obj)
Picks the coordinates and pixel value from the current mouse position in the window.
void textDisplay()
Toggles text in display.
QList< QAction * > actionsToAppend
Context actions to append.
QAction * contourNodePolyDataAct
Save contour surface nodes as polydata.
void addImageActor(vtkSmartPointer< vtkImageActor > imgActor, vtkMatrix4x4 *transformMatrix=NULL)
Directly add image actor to generic view.
QAction * refreshAct
Action for refreshing the display.
vtkSmartPointer< vtkAxesActor > orientAxes
Orientation (posterior etc.) axes for the orientation marker.
QAction * textAct
Action for angle measuring display.
QAction * contourInitAct
Load contour surface points from polydata.
bool scaleBefore
scale displayed?
bool contextMenuEnabled
Display orientation (posterior etc.) axes?
void enableActionBasedOnView()
Enables the view actions corresponding to current view set.
void contextMenuEvent(QContextMenuEvent *event)
The context menu setup member.
void contourAsPolyData()
Save contour as polydata/model. This saves all intermediate points, not just what the user places...
QMenu * contourMenu
Contour Menu.
virtual void colourMapToRainbow(double minRange=0.0, double maxRange=0.0)
Change the colour map to default VTK which is rainbow.
void createActions()
Create the actions for context menu etc.
void reset()
Reset the rendering, camera and windowing.
void dropEvent(QDropEvent *event)
Part of the Drag and Drop feature members. Opens the dropped files.
QAction * resetAct
Action for refreshing the display.
void contourAsNodePolyData()
Save contour as polydata/model. This only saves the points the user has placed.
QMenu * colourMapMenu
Colour map menu.
virtual void colourMapToCubeHelix(double minRange=0.0, double maxRange=0.0)
Change the colour map to CubeHelix.
void generateRender()
Generate the render so it is ready for display. Should be called before showing the window...
LabelledAction * actionHOT
HOT colours.
virtual void scaleDisplay(const bool forceDisplay=false)
Toggles the scale bar display.
virtual void disableScale()
Disables the scale bar display.
virtual void customOperation()
Custom operation, data dependent for viewing in unified environment. By default, this allows importin...
void linkProgressEventOf(vtkObject *obj)
Link the progress of filters etc to keep the UI responsive.
virtual void colourMapToLogGray(double minRange=0.0, double maxRange=0.0)
Change the colour map to Logarithmic (base 10) Gray.
void dragLeaveEvent(QDragLeaveEvent *event)
Part of the Drag and Drop feature members. Accepts drags.
QAction * saveViewAct
Save camera view.
virtual void enableCrosshair()
Enables the mouse pointer as a crosshair instead. Scene must be rendered before calling.
QAction * viewXY
Change view to xy-plane (Axial)
virtual void colourMapToCOOLWARM(double minRange=0.0, double maxRange=0.0)
Change the colour map to COOL.
QActionGroup * mapGroup
Grouping for check boxes.
void modelAvailable(vtkPolyData *, QString)
Send signal that an surface etc. is available for showing.
virtual void colourMapToGNUPlot(double minRange=0.0, double maxRange=0.0)
Change the colour map to GNUPlot.
QString getName()
Returns the name of the data.
vtkSmartPointer< vtkPlaneWidget > planeWidget
Used for drawing planes.
void lighting()
Toggles two sided lighting in display.
vtkSmartPointer< vtkCamera > camera
camera for the view
void removeImageActor(vtkSmartPointer< vtkImageActor > imgActor)
Directly remove image actor from generic view.
LabelledAction * actionGray
Gray colours.
QAction * actionCOOL
COOL colours.
virtual void colourMapToGray(double minRange=0.0, double maxRange=0.0)
Change the colour map to Gray.
bool rendered
Scene as been setup for rendering? (by generateRender())
virtual void viewToZYPlane()
Change view to zy-plane.
QList< QAction * > actionsToAdd
Context actions to add.
void setupHumanGlyph(vtkSmartPointer< vtkMatrix4x4 > mat=NULL)
Setup the human orientation glyph even if some transform if present between glyph and view...
vtkSmartPointer< vtkSphereWidget2 > sphereWidget
Used for measuring angles.
QAction * viewZX
Change view to zx-plane (Sagittal)
bool openModelUsingQt(const QString filename, vtkSmartPointer< vtkPolyData > &data)
Opens a model file using Qt file objects, which can be a Wavefront Object file (*.obj) only. This member is intended to be used with the Qt resource system.
LabelledAction * actionCOOLWARM
COOL colours.
void setView(int viewMode)
Change view to view mode identified by number. 0-axial, 1-coronal, 2-sagittal.
void axesDisplay()
Toggles the axes display.
LabelledAction * actionSeismic
Gray2 colours.
virtual void colourMapToHOT(double minRange=0.0, double maxRange=0.0)
Change the colour map to HOT.
vtkSmartPointer< vtkMatrix4x4 > getTransformMatrix()
Internal transform matrix used to transform actors appropriately for direction and coordinate systems...
QAction * distanceAct
Action for distance measuring display.
QList< vtkSmartPointer< vtkTextWidget > > textWidgets
Used for displaying movable texts in render window.
virtual ~milxQtRenderWindow()
The standard destructor.
virtual void colourMapToKnee(double minRange=0.0, double maxRange=0.0)
Change the colour map to Knee.
vtkSmartPointer< vtkSphereRepresentation > sphereRep
Sphere for widgets.
virtual void viewToXYPlane()
Change view to xy-plane.
virtual void colourMapToNIH_Fire(double minRange=0.0, double maxRange=0.0)
Change the colour map to NIH Fire.
QAction * biDirectionAct
Action for cross distance measuring display.
QList< vtkSmartPointer< vtkTextActor > > textActors
text actors for text widgets
milxQtRenderWindow(QWidget *theParent=0, bool contextSystem=true)
The standard constructor.
void dragMoveEvent(QDragMoveEvent *event)
Part of the Drag and Drop feature members. Accepts drags.
virtual vtkImageActor * GetImageActor()
Get the image actors, Implement in derived class that uses images.
void refresh()
Refresh the display of the model including widgets. Camera remains as is.
void crosshair()
Toggles corsshair.
vtkSmartPointer< vtkRenderWindow > renderWindow
Render Window used if no other set, only for deletion, access through QVTKWidget members.
QAction * actionFS
FS colours.
void printInfo(QString msg)
Info message wrapper for console.
virtual void colourMapToCOOL(double minRange=0.0, double maxRange=0.0)
Change the colour map to COOL.
bool useDefaultView
Using log scalar map?
QAction * actionAAL
AAL colours.
vtkSmartPointer< vtkEventQtSlotConnect > Connector
VTK Events to slots convertor.
void addActor(vtkSmartPointer< vtkActor > imgActor, vtkMatrix4x4 *transformMatrix=NULL)
Directly add actor to generic view with transform matrix.
vtkSmartPointer< vtkScalarBarWidget > scalarBar
Scalar Bar Widget for the display.
QMenu * windowPropertiesMenu
Context Menu.
virtual void colourMapToHSV(double minRange=0.0, double maxRange=0.0)
Change the colour map to HSV.
vtkRenderer * GetRenderer()
Returns the VTK Renderer object.
virtual void updateImageActor(vtkObject *obj, unsigned long, void *client_data, void *, vtkCommand *command)
Update any image actors in display to current slice when slice number changes.
virtual void background(bool white=false)
Changes background to white.
QAction * planeAct
Action for drawing planes.
QAction * angleAct
Action for angle measuring display.
void importFrom(milxQtRenderWindow *windowToImportFrom)
Import actors/scene directly from another renderwindow.
void contextMenuSystem(bool context)
Disable/enable context menu system, should be on by default otherwise VTK will steal all right click ...
QStatusBar * updateBar
Pointer to bar, not allocated or deleted. To be passed to only.
QList< QMenu * > menusToAppend
Context Menu's to append.
Represents a the various colour maps available for VTK scalars etc. Default: NIH. ...
QAction * loadViewAct
Load camera view.
void removeModelActor(vtkSmartPointer< vtkActor > mdlActor)
Directly remove model actor from generic view.
vtkSmartPointer< vtkPointPicker > dataPicker
For determining coordinates and points from the window.
void disableOrient()
Disables orientation marker.
virtual void SetupWidgets(vtkRenderWindowInteractor *interactor)
Update the interactor so that the widgets are usable. Call this if you change the render window or in...
QAction * sphereAct
Action for sphere annotate display.
void mouseDoubleClickEvent(QMouseEvent *event)
Part of the Drag and Drop feature members. Triggers the dragging on double click. ...
void loadView(QString filename="")
Saves the camera details to internal variables that can be restore anytime with loadView().
virtual void colourMapToJet(double minRange=0.0, double maxRange=0.0)
Change the colour map to Jet.
QAction * loadViewFileAct
Load camera view to file.