### Setup 3D Volume Rendering with vtkWidget3D Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Configures the vtkWidget3D for 3D volume rendering of DICOM series. It involves initializing the widget, setting up the DICOM reader, configuring the interactor, and applying a transfer function for visualization. The widget supports interactive cropping and various rendering modes. ```cpp #include "vtkwidget3d.h" #include "series.h" #include "transferfunction.h" #include #include #include #include #include #include using namespace asclepios::gui; // Setup 3D volume rendering for a series void setup3DVolumeRendering(QVTKOpenGLNativeWidget* vtkWidget, asclepios::core::Series* series) { // Create 3D visualization widget auto widget3D = vtkSmartPointer::New(); // Get volume reader for the entire series vtkSmartPointer reader = series->getReaderForAllSingleFrameImages(); // Setup render window interactor vtkSmartPointer interactor = vtkSmartPointer::New(); interactor->SetRenderWindow(vtkWidget->renderWindow()); widget3D->setInteractor(interactor); // Get the volume mapper and set input data vtkSmartVolumeMapper* mapper = widget3D->getvtkWidget3DSmartVolumeMapper(); mapper->SetInputConnection(reader->GetOutputPort()); // Load a preset transfer function filter (e.g., CT-Bone, CT-Soft Tissue) QString filterPath = ":/filters3d/BONES.json"; // Resource path or file path widget3D->setFilter(filterPath); // Update the filter to apply changes widget3D->updateFilter(); // Enable interactive box widget for cropping widget3D->activateBoxWidget(true); // Render the 3D scene widget3D->render(); // Disable box widget // widget3D->activateBoxWidget(false); // Load different preset filters // widget3D->setFilter(":/filters3d/GOLDBONE.json"); // widget3D->setFilter(":/filters3d/MIP.json"); // Maximum Intensity Projection // widget3D->updateFilter(); } ``` -------------------------------- ### Setup 2D DICOM Viewer (vtkWidget2D) Widget Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt This C++ function initializes and configures the vtkWidget2D, an interactive 2D DICOM viewer. It takes a QVTKOpenGLNativeWidget and an asclepios::core::Image object as input. The function sets the image reader, initializes the rendering pipeline, configures user interactions via an interactor, and updates overlay information such as image number, window/level, zoom factor, and HU values. It requires VTK and Qt (for QVTKOpenGLNativeWidget) libraries. ```cpp #include "vtkwidget2d.h" #include "image.h" #include #include #include #include using namespace asclepios::gui; // Setup 2D viewer for a DICOM image void setup2DViewer(QVTKOpenGLNativeWidget* vtkWidget, asclepios::core::Image* image) { // Create 2D visualization widget auto widget2D = vtkSmartPointer::New(); // Set the image reader vtkSmartPointer reader = image->getImageReader(); widget2D->setImageReader(reader); // Initialize the reader and render pipeline widget2D->initImageReader(); // Setup interactor for user interaction vtkSmartPointer interactor = vtkSmartPointer::New(); interactor->SetRenderWindow(vtkWidget->renderWindow()); widget2D->setInteractor(interactor); // Update overlay information widget2D->updateOvelayImageNumber( image->getIndex() + 1, // Current image number image->getParentObject()->getSinlgeFrameImages().size(), // Total images 1 // Number of series ); // Update window/level in overlay widget2D->updateOverlayWindowLevelApply( image->getWindowCenter(), image->getWindowWidth(), true ); // Update zoom factor display widget2D->updateOverlayZoomFactor(); // Update HU value at mouse position (e.g., x=100, y=100) widget2D->updateOverlayHUValue(100, 100); // Render the scene widget2D->render(); // Apply transformations (e.g., flip, rotate) // widget2D->applyTransformation(transformationType::FLIP_HORIZONTAL); // widget2D->applyTransformation(transformationType::ROTATE_90_CW); // Reset overlay to default state // widget2D->resetOverlay(); } ``` -------------------------------- ### Setup MPR Viewer with Orthogonal Views Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Configures the vtkWidgetMPR for interactive multiplanar reconstruction with three orthogonal views (axial, coronal, sagittal) and synchronized cursor navigation. It initializes the MPR widget, sets window/level parameters, identifies view numbers, and manages camera and cursor visibility. Requires vtkwidgetmpr.h, series.h, vtkDICOMReader, vtkRenderWindow, and QVTKOpenGLNativeWidget. ```cpp #include "vtkwidgetmpr.h" #include "series.h" #include #include #include using namespace asclepios::gui; // Setup MPR viewer with three orthogonal views void setupMPRViewer(QVTKOpenGLNativeWidget* axialWidget, QVTKOpenGLNativeWidget* coronalWidget, QVTKOpenGLNativeWidget* sagittalWidget, asclepios::core::Series* series) { // Create MPR widget auto widgetMPR = vtkSmartPointer::New(); // Get volume reader for the series vtkSmartPointer reader = series->getReaderForAllSingleFrameImages(); // Create 3D matrix from volume data widgetMPR->create3DMatrix(); // Set initial window/level for all views int windowCenter = 50; int windowWidth = 400; widgetMPR->setWindowLevel(windowCenter, windowWidth); // Change window/level for specific view vtkRenderWindow* axialRenderWindow = axialWidget->renderWindow(); widgetMPR->changeWindowLevel(axialRenderWindow, windowCenter, windowWidth, true); // Identify which view is which (returns 0, 1, or 2) int axialViewNumber = widgetMPR->getNumberOfRenderWindow(axialRenderWindow); int coronalViewNumber = widgetMPR->getNumberOfRenderWindow(coronalWidget->renderWindow()); int sagittalViewNumber = widgetMPR->getNumberOfRenderWindow(sagittalWidget->renderWindow()); std::cout << "Axial View: " << axialViewNumber << std::endl; std::cout << "Coronal View: " << coronalViewNumber << std::endl; std::cout << "Sagittal View: " << sagittalViewNumber << std::endl; // Set active render window for interaction widgetMPR->setActiveRenderWindow(axialRenderWindow); // Center camera on all views widgetMPR->setCameraCentered(1); // Show or hide crosshair cursor widgetMPR->setShowCursor(true); // Show crosshair // widgetMPR->setShowCursor(false); // Hide crosshair // Reset reslice widget to initial position widgetMPR->resetResliceWidget(); // Render all views widgetMPR->render(); } ``` -------------------------------- ### Main Application Entry Point Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Initializes the Qt application, VTK modules, and the GUI framework. It sets up high DPI scaling, disables VTK warnings, sets the application icon, creates the main GUI components (GUIFrame and GUI), and displays the maximized window. Requires QApplication, QIcon, VTK modules, gui.h, and guiframe.h. ```cpp #include #include #include #include #include "gui.h" #include "guiframe.h" // Initialize VTK modules VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT(vtkInteractionStyle); VTK_MODULE_INIT(vtkRenderingFreeType); VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2); int main(int argc, char* argv[]) { // Enable high DPI scaling for modern displays QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // Create Qt application QApplication application(argc, argv); // Disable VTK warning messages vtkObject::GlobalWarningDisplayOff(); // Set application icon application.setWindowIcon(QIcon(":/res/coronavirus_icon.png")); // Create GUI components asclepios::gui::GUIFrame guiFrame; // Frameless window container asclepios::gui::GUI gui; // Main GUI widget // Set GUI content in the frameless window guiFrame.setContent(&gui); // Show maximized window guiFrame.showMaximized(); // Start application event loop return application.exec(); } ``` -------------------------------- ### Load DICOM Directory and Process Files - C++ Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt This C++ function, `loadDicomDirectory`, iterates through a specified directory, reads DICOM files using `CoreController`, and reports on newly added series and images. It provides summary statistics on processed files, patients, and new series. Dependencies include ``, ``, and ``. ```cpp #include "corecontroller.h" #include #include #include using namespace asclepios::core; namespace fs = std::filesystem; // Load multiple DICOM files and organize them by patient/study/series void loadDicomDirectory(const std::string& directoryPath) { CoreController controller; int filesProcessed = 0; int newSeriesCount = 0; // Iterate through all DICOM files in directory for (const auto& entry : fs::recursive_directory_iterator(directoryPath)) { if (entry.is_regular_file()) { std::string filepath = entry.path().string(); // Read the DICOM file controller.readData(filepath); // Check if a new series was added if (controller.newSeriesAdded()) { newSeriesCount++; auto* series = controller.getLastSeries(); std::cout << "New Series Added: " << series->getDescription() << " (UID: " << series->getUID() << ")" << std::endl; } // Display info about the last image added if (controller.newImageAdded()) { auto* image = controller.getLastImage(); std::cout << " Image " << (image->getIndex() + 1) << ": " << image->getImagePath() << std::endl; } filesProcessed++; } } // Display summary statistics std::cout << "\n=== Summary ===" << std::endl; std::cout << "Files Processed: " << filesProcessed << std::endl; std::cout << "Total Patients: " << controller.getPatients().size() << std::endl; std::cout << "New Series Detected: " << newSeriesCount << std::endl; // Access the last series data if (controller.getLastSeries()) { std::cout << "Last Series Size: " << controller.getLastSeriesSize() << " images" << std::endl; std::cout << "Last Series Index: " << controller.getLastSeriesIndex() << std::endl; } // Optionally reset all data // controller.resetData(); } ``` -------------------------------- ### Load DICOM Files and Organize with C++ CoreController Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt This C++ code defines a DicomLoader class that utilizes the CoreController to load DICOM files from a specified directory. It organizes the loaded data into patients, studies, and series, tracks image counts, and reports loading errors. Dependencies include standard C++ libraries like filesystem, iostream, and vector, along with project-specific headers. ```cpp #include "corecontroller.h" #include "patient.h" #include "study.h" #include "series.h" #include "image.h" #include #include #include using namespace asclepios::core; namespace fs = std::filesystem; // Complete DICOM loading and organization workflow class DicomLoader { public: DicomLoader() : controller(std::make_unique()) {} void loadDirectory(const std::string& path) { std::cout << "Loading DICOM files from: " << path << std::endl; for (const auto& entry : fs::recursive_directory_iterator(path)) { if (entry.is_regular_file()) { loadFile(entry.path().string()); } } displaySummary(); } void loadFile(const std::string& filepath) { try { controller->readData(filepath); if (controller->newSeriesAdded()) { Series* series = controller->getLastSeries(); seriesCount++; std::cout << "New series: " << series->getDescription() << std::endl; } if (controller->newImageAdded()) { imageCount++; } } catch (const std::exception& e) { std::cerr << "Error loading " << filepath << ": " << e.what() << std::endl; errorCount++; } } void displaySummary() { std::cout << "\n=== Loading Summary ===" << std::endl; std::cout << "Total Patients: " << controller->getPatients().size() << std::endl; std::cout << "Total Series: " << seriesCount << std::endl; std::cout << "Total Images: " << imageCount << std::endl; std::cout << "Errors: " << errorCount << std::endl; } Series* getLastLoadedSeries() { return controller->getLastSeries(); } Image* getLastLoadedImage() { return controller->getLastImage(); } std::vector>& getAllPatients() { return controller->getPatients(); } void reset() { controller->resetData(); seriesCount = 0; imageCount = 0; errorCount = 0; } private: std::unique_ptr controller; int seriesCount = 0; int imageCount = 0; int errorCount = 0; }; // Usage example int main() { DicomLoader loader; // Load DICOM files from directory loader.loadDirectory("/path/to/dicom/studies"); // Get last loaded series for visualization Series* series = loader.getLastLoadedSeries(); if (series) { std::cout << "Ready to visualize series: " << series->getUID() << std::endl; std::cout << "Number of images: " << series->getSinlgeFrameImages().size() << std::endl; } // Iterate through all loaded data auto& patients = loader.getAllPatients(); for (auto& patient : patients) { std::cout << "Patient: " << patient->getName() << std::endl; for (auto& study : patient->getStudies()) { std::cout << " Study: " << study->getDescription() << std::endl; for (auto& seriesItem : study->getSeries()) { std::cout << " Series: " << seriesItem->getDescription() << " (" << seriesItem->getSinlgeFrameImages().size() << " images)" << std::endl; } } } return 0; } ``` -------------------------------- ### Create 3D Volume from DICOM Series using VTK Reader Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt This C++ function demonstrates how to obtain a VTK reader for a series of DICOM images, which are automatically sorted for 3D volume reconstruction. It accesses the 3D volume data, retrieves DICOM metadata, and navigates through individual images within the series. Dependencies include VTK libraries for DICOM reading and image data handling. ```cpp #include "series.h" #include #include #include #include #include using namespace asclepios::core; // Create 3D volume from series for volume rendering or MPR void create3DVolumeFromSeries(Series* series) { // Get VTK reader for all single-frame images (sorted automatically) vtkSmartPointer reader = series->getReaderForAllSingleFrameImages(); if (!reader) { std::cerr << "Failed to create reader for series" << std::endl; return; } // Access 3D volume data vtkImageData* volumeData = reader->GetOutput(); int* dims = volumeData->GetDimensions(); std::cout << "3D Volume Dimensions: " << dims[0] << "x" << dims[1] << "x" << dims[2] << std::endl; std::cout << "Total slices: " << dims[2] << std::endl; // Get DICOM metadata for the series vtkSmartPointer metadata = series->getMetaDataForSeries(); if (metadata) { std::cout << "Metadata successfully loaded" << std::endl; } // Navigate through images in the series Image* currentImage = series->getSingleFrameImageByIndex(0); std::cout << "First Image - Slice Location: " << currentImage->getSliceLocation() << std::endl; // Get next and previous images Image* nextImage = series->getNextSingleFrameImage(currentImage); Image* prevImage = series->getPreviousSingleFrameImage(currentImage); // Access specific image by index int totalImages = series->getSinlgeFrameImages().size(); for (int i = 0; i < totalImages; i++) { Image* img = series->getSingleFrameImageByIndex(i); std::cout << "Image " << i << " - Instance: " << img->getInstanceNumber() << std::endl; } } ``` -------------------------------- ### Display DICOM Hierarchy in C++ Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Navigates and displays the complete DICOM hierarchy, including patients, studies, and series. It iterates through nested data structures and accesses image information. Dependencies include core controller and data model classes like Patient, Study, Series, and Image. ```cpp #include "corecontroller.h" #include "patient.h" #include "study.h" #include "series.h" #include "image.h" #include using namespace asclepios::core; // Navigate and display the complete DICOM hierarchy void displayDicomHierarchy(CoreController& controller) { auto& patients = controller.getPatients(); for (auto& patientPtr : patients) { Patient* patient = patientPtr.get(); std::cout << "Patient: " << patient->getName() << " (ID: " << patient->getID() << ")" << std::endl; std::cout << " Age: " << patient->getAge() << ", Birth Date: " << patient->getBirthDate() << std::endl; // Iterate through all studies for this patient auto& studies = patient->getStudies(); for (auto& studyPtr : studies) { Study* study = studyPtr.get(); std::cout << " Study: " << study->getDescription() << " (Date: " << study->getDate() << ")" << std::endl; // Iterate through all series for this study auto& seriesList = study->getSeries(); for (auto& seriesPtr : seriesList) { Series* series = seriesPtr.get(); std::cout << " Series #" << series->getNumber() << ": " << series->getDescription() << std::endl; // Access single-frame images in this series auto& singleFrameImages = series->getSinlgeFrameImages(); std::cout << " Single-frame images: " << singleFrameImages.size() << std::endl; // Access multi-frame images in this series auto& multiFrameImages = series->getMultiFrameImages(); std::cout << " Multi-frame images: " << multiFrameImages.size() << std::endl; // Example: Navigate through single-frame images if (!singleFrameImages.empty()) { Image* firstImage = singleFrameImages.begin()->get(); std::cout << " First Image - Modality: " << firstImage->getModality() << ", Dimensions: " << firstImage->getRows() << "x" << firstImage->getColumns() << std::endl; // Get next image in series Image* nextImage = series->getNextSingleFrameImage(firstImage); if (nextImage != firstImage) { std::cout << " Next Image - Instance: " << nextImage->getInstanceNumber() << std::endl; } } } } } } ``` -------------------------------- ### Create Custom Volume Appearance with TransferFunction Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Manages the color and opacity mapping for 3D volume rendering using the TransferFunction class. This enables customization of tissue appearance by loading filters from JSON files and applying properties like window/level, ambient, diffuse, and specular values to a vtkVolume. ```cpp #include "transferfunction.h" #include #include #include #include #include #include using namespace asclepios::gui; // Create and apply custom transfer function for bone rendering void setupBoneTransferFunction(vtkVolume* volume) { TransferFunction transferFunc; // Load predefined filter from JSON file QString filterFile = ":/filters3d/BONES.json"; transferFunc.loadFilterFromFile(filterFile); // Get transfer function properties std::cout << "Window: " << transferFunc.getWindow() << std::endl; std::cout << "Level: " << transferFunc.getLevel() << std::endl; std::cout << "Ambient: " << transferFunc.getAmbient() << std::endl; std::cout << "Diffuse: " << transferFunc.getDiffuse() << std::endl; std::cout << "Specular: " << transferFunc.getSpecular() << std::endl; std::cout << "Specular Power: " << transferFunc.getSpecularPower() << std::endl; std::cout << "Has Shade: " << (transferFunc.getHasShade() ? "Yes" : "No") << std::endl; // Apply to volume property vtkVolumeProperty* volumeProperty = volume->GetProperty(); volumeProperty->SetColor(transferFunc.getColorFunction()); volumeProperty->SetScalarOpacity(transferFunc.getOpacityFunction()); volumeProperty->SetAmbient(transferFunc.getAmbient()); volumeProperty->SetDiffuse(transferFunc.getDiffuse()); volumeProperty->SetSpecular(transferFunc.getSpecular()); volumeProperty->SetSpecularPower(transferFunc.getSpecularPower()); volumeProperty->SetShade(transferFunc.getHasShade()); // Update window/level dynamically transferFunc.updateWindowLevel(500, 1500); // Bone window/level } // Create MIP (Maximum Intensity Projection) transfer function void setupMIPRendering(vtkVolume* volume, int windowCenter, int windowWidth) { TransferFunction transferFunc; // Set MIP-specific transfer function transferFunc.setMaximumIntensityProjectionFunction(windowCenter, windowWidth); // Apply to volume vtkVolumeProperty* volumeProperty = volume->GetProperty(); volumeProperty->SetColor(transferFunc.getColorFunction()); volumeProperty->SetScalarOpacity(transferFunc.getOpacityFunction()); // Disable shading for MIP volumeProperty->SetShade(false); } ``` -------------------------------- ### Read DICOM Files and Extract Metadata - C++ Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt This C++ code snippet demonstrates how to use the DicomReader class to read a DICOM file, parse its metadata, and extract patient, study, series, and image information. It includes error handling for file loading failures and checks for unsupported modalities. Dependencies include the DicomReader class and standard C++ libraries. ```cpp #include "dicomreader.h" #include #include using namespace asclepios::core; // Read a DICOM file and extract all metadata void processAndDisplayDicomFile(const std::string& filepath) { DicomReader reader; try { // Load and parse the DICOM file reader.readFile(filepath); // Verify the dataset was successfully loaded if (!reader.dataSetExists()) { std::cerr << "Failed to load DICOM dataset" << std::endl; return; } // Extract patient information auto patient = reader.getReadPatient(); std::cout << "Patient Name: " << patient->getName() << std::endl; std::cout << "Patient ID: " << patient->getID() << std::endl; std::cout << "Patient Age: " << patient->getAge() << std::endl; std::cout << "Birth Date: " << patient->getBirthDate() << std::endl; // Extract study information auto study = reader.getReadStudy(); std::cout << "Study UID: " << study->getUID() << std::endl; std::cout << "Study ID: " << study->getID() << std::endl; std::cout << "Study Date: " << study->getDate() << std::endl; std::cout << "Study Description: " << study->getDescription() << std::endl; // Extract series information (returns nullptr for unsupported modalities) auto series = reader.getReadSeries(); if (series) { std::cout << "Series UID: " << series->getUID() << std::endl; std::cout << "Series Number: " << series->getNumber() << std::endl; std::cout << "Series Description: " << series->getDescription() << std::endl; // Extract image information auto image = reader.getReadImage(); std::cout << "Image Modality: " << image->getModality() << std::endl; std::cout << "Window Center: " << image->getWindowCenter() << std::endl; std::cout << "Window Width: " << image->getWindowWidth() << std::endl; std::cout << "Dimensions: " << image->getRows() << "x" << image->getColumns() << std::endl; std::cout << "Slice Location: " << image->getSliceLocation() << std::endl; std::cout << "Number of Frames: " << image->getNumberOfFrames() << std::endl; std::cout << "Is Multi-frame: " << (image->getIsMultiFrame() ? "Yes" : "No") << std::endl; } else { std::cout << "Unsupported modality (PR, KO, or SR)" << std::endl; } } catch (const std::runtime_error& e) { std::cerr << "Error reading DICOM file: " << e.what() << std::endl; } } ``` -------------------------------- ### Read DICOM Image Properties with VTK in C++ Source: https://context7.com/gavrilovicieduard/asclepios-dicom-viewer/llms.txt Loads and displays properties of a DICOM image using a VTK DICOM reader. The reader is lazily initialized and cached. It accesses VTK image data to retrieve dimensions, spacing, origin, and scalar range. Dependencies include the Image class and VTK libraries. ```cpp #include "image.h" #include "series.h" #include #include #include #include using namespace asclepios::core; // Load and display image properties using VTK reader void displayImageWithVTK(Image* image) { // Get VTK reader for this image (creates if not exists) vtkSmartPointer reader = image->getImageReader(); // Access the image data vtkImageData* imageData = reader->GetOutput(); // Display VTK image properties int* dims = imageData->GetDimensions(); std::cout << "VTK Image Dimensions: " << dims[0] << "x" << dims[1] << "x" << dims[2] << std::endl; double* spacing = imageData->GetSpacing(); std::cout << "Pixel Spacing: " << spacing[0] << ", " << spacing[1] << ", " << spacing[2] << std::endl; double* origin = imageData->GetOrigin(); std::cout << "Image Origin: " << origin[0] << ", " << origin[1] << ", " << origin[2] << std::endl; // Access scalar range for window/level calculations double* range = imageData->GetScalarRange(); std::cout << "Scalar Range: [" << range[0] << ", " << range[1] << "]" << std::endl; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.