├── README.md ├── requirements.txt └── src ├── CMakeLists.txt ├── ConfidenceConnected3D.h ├── FixedPointVolumeRayCastMapperCT.h ├── PROJECT.cxx ├── itkWaterShedCode.h ├── readDICOMSeries.h └── vtkVolumeRenderer.h /README.md: -------------------------------------------------------------------------------- 1 | # Medical-Data-Visualization-3D 2 | A medical data visualization program. 3 | 9 | 10 | ## Guideline 11 | 19 | 20 | ## Technologies Used 21 | 28 | 29 | # Screenshots 30 | ![image](https://user-images.githubusercontent.com/36689470/66020013-832ff200-e507-11e9-8f65-e1b60032b28c.png) ![image](https://user-images.githubusercontent.com/36689470/66020054-9e026680-e507-11e9-87c5-563f4fad9bed.png) ![image](https://user-images.githubusercontent.com/36689470/66020132-defa7b00-e507-11e9-9af2-ac55ea4dc90f.png) ![image](https://user-images.githubusercontent.com/36689470/66020154-f46fa500-e507-11e9-811c-865212b95a84.png) 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | 1. Visual Studio >= 2015 2 | 2. CMake 3 | 3. VTK ( https://www.youtube.com/watch?v=IgvbhyDh8r0 ) 4 | 4. ITK ( https://www.youtube.com/watch?v=vZOMu5YSfoI ) 5 | 6 | PS. Remember to "Run as Administrator" -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | PROJECT(PROJECT) 3 | 4 | FIND_PACKAGE(VTK) 5 | IF(VTK_FOUND) 6 | INCLUDE(${VTK_USE_FILE}) 7 | ENDIF(VTK_FOUND) 8 | 9 | FIND_PACKAGE(ITK) 10 | include(${ITK_USE_FILE}) 11 | if (ITKVtkGlue_LOADED) 12 | find_package(VTK REQUIRED) 13 | include(${VTK_USE_FILE}) 14 | else() 15 | find_package(ItkVtkGlue REQUIRED) 16 | include(${ItkVtkGlue_USE_FILE}) 17 | set(Glue ItkVtkGlue) 18 | endif() 19 | 20 | add_executable(PROJECT MACOSX_BUNDLE PROJECT.cxx) 21 | 22 | TARGET_LINK_LIBRARIES(PROJECT ${Glue} ${ITK_LIBRARIES} ${VTK_LIBRARIES}) 23 | -------------------------------------------------------------------------------- /src/ConfidenceConnected3D.h: -------------------------------------------------------------------------------- 1 | #include "itkConfidenceConnectedImageFilter.h" 2 | #include "itkCastImageFilter.h" 3 | #include "itkCurvatureFlowImageFilter.h" 4 | #include "itkImageFileReader.h" 5 | #include "itkImageFileWriter.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "itkVTKImageExport.h" 24 | #include "itkVTKImageImport.h" 25 | 26 | #include "vtkImageImport.h" 27 | #include "vtkImageExport.h" 28 | #include "vtkImageActor.h" 29 | 30 | template void ConnectPipelines2(ITK_Exporter exporter, VTK_Importer* importer) 31 | { 32 | importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); 33 | importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); 34 | importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); 35 | importer->SetSpacingCallback(exporter->GetSpacingCallback()); 36 | importer->SetOriginCallback(exporter->GetOriginCallback()); 37 | importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); 38 | importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); 39 | importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); 40 | importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); 41 | importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); 42 | importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); 43 | importer->SetCallbackUserData(exporter->GetCallbackUserData()); 44 | } 45 | 46 | template void ConnectPipelines2(VTK_Exporter* exporter, ITK_Importer importer) 47 | { 48 | importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); 49 | importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); 50 | importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); 51 | importer->SetSpacingCallback(exporter->GetSpacingCallback()); 52 | importer->SetOriginCallback(exporter->GetOriginCallback()); 53 | importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); 54 | importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); 55 | importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); 56 | importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); 57 | importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); 58 | importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); 59 | importer->SetCallbackUserData(exporter->GetCallbackUserData()); 60 | } 61 | 62 | 63 | char buffer[1000]; 64 | char tmp[1000]; 65 | 66 | void getFileName(char *inputFile) 67 | { 68 | int l = strlen(inputFile); 69 | int x = 0; 70 | for(int i = l-1; i>-1; i--) 71 | { 72 | if(inputFile[i]=='\\') 73 | break; 74 | buffer[x] = inputFile[i]; 75 | x++; 76 | } 77 | strrev(buffer); 78 | //strcat(buffer,".mha"); 79 | return; 80 | } 81 | 82 | void getOutputPath(char *inputFile) 83 | { 84 | int l = strlen(inputFile); 85 | int x = 0; 86 | bool flag = false; 87 | for(int i = l-1; i>-1; i--) 88 | { 89 | if(inputFile[i]=='\\' && !flag) 90 | flag = true; 91 | if(flag) 92 | { 93 | tmp[x] = inputFile[i]; 94 | x++; 95 | } 96 | } 97 | strrev(tmp); 98 | return; 99 | } 100 | 101 | 102 | void confidenceSeg() 103 | { 104 | 105 | cout<< "Enter input image file path: "; 106 | char inputImagePath[1000]; 107 | cin>>inputImagePath; 108 | 109 | // char outputImageName[1000]; 110 | // getFileName(inputImagePath); 111 | // strcpy(outputImageName,"Segmented_"); 112 | // strcat(outputImageName,buffer); 113 | 114 | typedef float InternalPixelType; 115 | const unsigned int Dimension = 3; 116 | typedef itk::Image< InternalPixelType, Dimension > InternalImageType; 117 | 118 | typedef unsigned char OutputPixelType; 119 | typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 120 | OutputImageType::Pointer image; 121 | 122 | typedef itk::CastImageFilter< InternalImageType, OutputImageType > CastingFilterType; 123 | CastingFilterType::Pointer caster = CastingFilterType::New(); 124 | 125 | 126 | typedef itk::ImageFileReader< InternalImageType > ReaderType; 127 | //typedef itk::ImageFileWriter< OutputImageType > WriterType; 128 | 129 | ReaderType::Pointer reader = ReaderType::New(); 130 | //WriterType::Pointer writer = WriterType::New(); 131 | 132 | reader->SetFileName( inputImagePath ); 133 | //writer->SetFileName( outputImageName ); 134 | 135 | typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType > CurvatureFlowImageFilterType; 136 | CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New(); 137 | 138 | typedef itk::ConfidenceConnectedImageFilter ConnectedFilterType; 139 | ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New(); 140 | 141 | smoothing->SetInput( reader->GetOutput() ); 142 | confidenceConnected->SetInput( smoothing->GetOutput() ); 143 | caster->SetInput( confidenceConnected->GetOutput() ); 144 | //writer->SetInput( caster->GetOutput() ); 145 | 146 | smoothing->SetNumberOfIterations( 7 ); 147 | smoothing->SetTimeStep( 0.05 ); 148 | 149 | confidenceConnected->SetMultiplier( 2.5 ); 150 | confidenceConnected->SetNumberOfIterations( 5 ); 151 | confidenceConnected->SetInitialNeighborhoodRadius( 2 ); 152 | confidenceConnected->SetReplaceValue( 255 ); 153 | 154 | InternalImageType::IndexType index1; 155 | index1[0] = 118; 156 | index1[1] = 133; 157 | index1[2] = 92; 158 | confidenceConnected->AddSeed( index1 ); 159 | 160 | InternalImageType::IndexType index2; 161 | index2[0] = 63; 162 | index2[1] = 135; 163 | index2[2] = 94; 164 | confidenceConnected->AddSeed( index2 ); 165 | 166 | InternalImageType::IndexType index3; 167 | index3[0] = 63; 168 | index3[1] = 157; 169 | index3[2] = 90; 170 | confidenceConnected->AddSeed( index3 ); 171 | 172 | InternalImageType::IndexType index4; 173 | index4[0] = 111; 174 | index4[1] = 150; 175 | index4[2] = 90; 176 | confidenceConnected->AddSeed( index4 ); 177 | 178 | InternalImageType::IndexType index5; 179 | index5[0] = 111; 180 | index5[1] = 50; 181 | index5[2] = 88; 182 | confidenceConnected->AddSeed( index5 ); 183 | 184 | // VTK Pipeline 185 | 186 | typedef itk::VTKImageExport< OutputImageType > ExportFilterType; // 187 | ExportFilterType::Pointer itkExporter = ExportFilterType::New(); // 188 | 189 | itkExporter->SetInput(caster->GetOutput()); // 190 | 191 | vtkImageImport* vtkImporter = vtkImageImport::New(); // 192 | ConnectPipelines2(itkExporter, vtkImporter); 193 | 194 | 195 | typedef itk::VTKImageImport< OutputImageType > ImportFilterType; // 196 | ImportFilterType::Pointer itkImporter = ImportFilterType::New(); // 197 | 198 | 199 | vtkImageExport* vtkExporter = vtkImageExport::New(); 200 | ConnectPipelines2(vtkExporter, itkImporter); 201 | 202 | #if VTK_MAJOR_VERSION <= 5 203 | vtkExporter->SetInput(vtkImporter->GetOutput()); 204 | #else 205 | vtkImporter->Update(); 206 | vtkExporter->SetInputData(vtkImporter->GetOutput()); 207 | #endif 208 | 209 | //vtkImageActor* actor = vtkImageActor::New(); 210 | vtkImageData *imageData = vtkImageData::New(); 211 | #if VTK_MAJOR_VERSION <= 5 212 | //actor->SetInput(vtkImporter->GetOutput()); 213 | imageData->ShallowCopy(vtkImporter->GetOutput()); 214 | #else 215 | //actor->SetInputData(vtkImporter->GetOutput()); 216 | imageData->ShallowCopy(vtkImporter->GetOutput()); 217 | #endif 218 | 219 | vtkGPUVolumeRayCastMapper *mapperVolume = vtkGPUVolumeRayCastMapper::New(); 220 | mapperVolume->SetBlendModeToComposite(); 221 | mapperVolume->SetInputData(imageData); 222 | 223 | vtkPiecewiseFunction *gradientOpacity = vtkPiecewiseFunction::New(); 224 | 225 | gradientOpacity->AddPoint(1, 0.0); 226 | gradientOpacity->AddPoint(5, 0.1); 227 | gradientOpacity->AddPoint(100, 1.0); 228 | 229 | vtkPiecewiseFunction *scalarOpacity = vtkPiecewiseFunction::New(); 230 | 231 | scalarOpacity->AddPoint(0, 0.0); 232 | for (int i = 1; i < 150; i++) 233 | { 234 | scalarOpacity->AddPoint(i, 0.25); 235 | } 236 | 237 | vtkColorTransferFunction *color = vtkColorTransferFunction::New(); 238 | 239 | color->AddRGBPoint(0, 0.0, 0.0, 0.0); 240 | color->AddRGBPoint(1, 0.9607843137254902, 0.9607843137254902, 0.9607843137254902); 241 | color->AddRGBPoint(2, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 242 | color->AddRGBPoint(3, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 243 | color->AddRGBPoint(4, 0.8666666666666667, 0.9725490196078431, 0.6431372549019608); 244 | color->AddRGBPoint(5, 0.9019607843137255, 0.5803921568627451, 0.13333333333333333); 245 | color->AddRGBPoint(6, 0.0, 0.4627450980392157, 0.054901960784313725); 246 | color->AddRGBPoint(7, 0.47843137254901963, 0.7294117647058823, 0.8627450980392157); 247 | color->AddRGBPoint(8, 0.9254901960784314, 0.050980392156862744, 0.6901960784313725); 248 | color->AddRGBPoint(9, 0.047058823529411764, 0.18823529411764706, 1.0); 249 | color->AddRGBPoint(10, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 250 | color->AddRGBPoint(11, 0.8627450980392157, 0.8470588235294118, 0.0784313725490196); 251 | color->AddRGBPoint(12, 0.403921568627451, 1.0, 1.0); 252 | color->AddRGBPoint(13, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 253 | color->AddRGBPoint(14, 1.0, 0.6470588235294118, 0.0); 254 | color->AddRGBPoint(15, 0.6470588235294118, 0.0, 1.0); 255 | color->AddRGBPoint(16, 0.6470588235294118, 0.16470588235294117, 0.16470588235294117); 256 | color->AddRGBPoint(17, 0.2, 0.19607843137254902, 0.5294117647058824); 257 | color->AddRGBPoint(18, 0.803921568627451, 0.24313725490196078, 0.3058823529411765); 258 | color->AddRGBPoint(19, 0.9607843137254902, 0.9607843137254902, 0.9607843137254902); 259 | color->AddRGBPoint(20, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 260 | color->AddRGBPoint(21, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 261 | color->AddRGBPoint(22, 0.8666666666666667, 0.9725490196078431, 0.6431372549019608); 262 | color->AddRGBPoint(23, 0.9019607843137255, 0.5803921568627451, 0.13333333333333333); 263 | color->AddRGBPoint(24, 0.0, 0.4627450980392157, 0.054901960784313725); 264 | color->AddRGBPoint(25, 0.47843137254901963, 0.7294117647058823, 0.8627450980392157); 265 | color->AddRGBPoint(26, 0.9254901960784314, 0.050980392156862744, 0.6901960784313725); 266 | color->AddRGBPoint(27, 0.050980392156862744, 0.18823529411764706, 1.0); 267 | color->AddRGBPoint(28, 0.8627450980392157, 0.8470588235294118, 0.0784313725490196); 268 | color->AddRGBPoint(29, 0.403921568627451, 1.0, 1.0); 269 | color->AddRGBPoint(30, 1.0, 0.6470588235294118, 0.0); 270 | color->AddRGBPoint(31, 0.6470588235294118, 0.16470588235294117, 0.16470588235294117); 271 | color->AddRGBPoint(32, 0.5294117647058824, 0.807843137254902, 0.9215686274509803); 272 | color->AddRGBPoint(33, 0.47843137254901963, 0.5294117647058824, 0.19607843137254902); 273 | color->AddRGBPoint(34, 0.47843137254901963, 0.5294117647058824, 0.19607843137254902); 274 | color->AddRGBPoint(35, 0.47058823529411764, 0.7450980392156863, 0.5882352941176471); 275 | color->AddRGBPoint(36, 1.0, 0.5803921568627451, 0.0392156862745098); 276 | color->AddRGBPoint(37, 1.0, 0.5803921568627451, 0.0392156862745098); 277 | color->AddRGBPoint(38, 0.050980392156862744, 0.18823529411764706, 1.0); 278 | color->AddRGBPoint(39, 1.0, 0.8549019607843137, 0.7254901960784313); 279 | color->AddRGBPoint(40, 0.9176470588235294, 0.6627450980392157, 0.11764705882352941); 280 | color->AddRGBPoint(41, 0.803921568627451, 0.0392156862745098, 0.49019607843137253); 281 | color->AddRGBPoint(42, 0.48627450980392156, 0.5490196078431373, 0.6980392156862745); 282 | color->AddRGBPoint(43, 0.8666666666666667, 0.8862745098039215, 0.26666666666666666); 283 | color->AddRGBPoint(44, 0.0, 0.19607843137254902, 0.5019607843137255); 284 | color->AddRGBPoint(45, 1.0, 0.8, 0.4); 285 | color->AddRGBPoint(46, 0.7843137254901961, 0.7843137254901961, 0.7843137254901961); 286 | color->AddRGBPoint(47, 0.7843137254901961, 0.7843137254901961, 0.7843137254901961); 287 | color->AddRGBPoint(48, 0.49019607843137253, 0.9803921568627451, 0.08235294117647059); 288 | color->AddRGBPoint(49, 0.49019607843137253, 0.9803921568627451, 0.08235294117647059); 289 | color->AddRGBPoint(50, 0.4, 0.6980392156862745, 1.0); 290 | color->AddRGBPoint(51, 0.4, 0.6980392156862745, 1.0); 291 | color->AddRGBPoint(52, 0.24705882352941178, 0.40784313725490196, 0.8784313725490196); 292 | color->AddRGBPoint(53, 0.24705882352941178, 0.40784313725490196, 0.8784313725490196); 293 | color->AddRGBPoint(54, 1.0, 0.09803921568627451, 0.4980392156862745); 294 | color->AddRGBPoint(55, 1.0, 0.09803921568627451, 0.4980392156862745); 295 | color->AddRGBPoint(56, 0.23529411764705882, 0.7411764705882353, 0.5098039215686274); 296 | color->AddRGBPoint(57, 0.23529411764705882, 0.7411764705882353, 0.5098039215686274); 297 | color->AddRGBPoint(58, 0.7372549019607844, 0.7098039215686275, 0.4117647058823529); 298 | color->AddRGBPoint(59, 0.7372549019607844, 0.7098039215686275, 0.4117647058823529); 299 | color->AddRGBPoint(60, 0.996078431372549, 0.8352941176470589, 0.0); 300 | color->AddRGBPoint(61, 0.996078431372549, 0.8352941176470589, 0.0); 301 | color->AddRGBPoint(62, 0.23529411764705882, 0.7058823529411765, 0.7058823529411765); 302 | color->AddRGBPoint(63, 0.23529411764705882, 0.7058823529411765, 0.7058823529411765); 303 | color->AddRGBPoint(64, 0.8, 0.4980392156862745, 0.0); 304 | color->AddRGBPoint(65, 0.8, 0.4980392156862745, 0.0); 305 | color->AddRGBPoint(66, 0.6862745098039216, 0.7607843137254902, 0.8666666666666667); 306 | color->AddRGBPoint(67, 0.6862745098039216, 0.7607843137254902, 0.8666666666666667); 307 | color->AddRGBPoint(68, 0.8823529411764706, 0.6549019607843137, 0.40784313725490196); 308 | color->AddRGBPoint(69, 0.8823529411764706, 0.6549019607843137, 0.40784313725490196); 309 | color->AddRGBPoint(70, 0.8980392156862745, 0.4980392156862745, 0.4980392156862745); 310 | color->AddRGBPoint(71, 0.8980392156862745, 0.4980392156862745, 0.4980392156862745); 311 | color->AddRGBPoint(72, 0.49019607843137253, 0.0196078431372549, 0.09803921568627451); 312 | color->AddRGBPoint(73, 0.09803921568627451, 0.39215686274509803, 0.1568627450980392); 313 | color->AddRGBPoint(74, 0.49019607843137253, 0.39215686274509803, 0.6274509803921569); 314 | color->AddRGBPoint(75, 0.39215686274509803, 0.09803921568627451, 0.0); 315 | color->AddRGBPoint(76, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 316 | color->AddRGBPoint(77, 0.8627450980392157, 0.0784313725490196, 0.0392156862745098); 317 | color->AddRGBPoint(78, 0.7058823529411765, 0.8627450980392157, 0.5490196078431373); 318 | color->AddRGBPoint(79, 0.8627450980392157, 0.23529411764705882, 0.8627450980392157); 319 | color->AddRGBPoint(80, 0.7058823529411765, 0.1568627450980392, 0.47058823529411764); 320 | color->AddRGBPoint(81, 0.5490196078431373, 0.0784313725490196, 0.5490196078431373); 321 | color->AddRGBPoint(82, 0.0784313725490196, 0.11764705882352941, 0.5490196078431373); 322 | color->AddRGBPoint(83, 0.13725490196078433, 0.29411764705882354, 0.19607843137254902); 323 | color->AddRGBPoint(84, 0.8823529411764706, 0.5490196078431373, 0.5490196078431373); 324 | color->AddRGBPoint(85, 0.7843137254901961, 0.13725490196078433, 0.29411764705882354); 325 | color->AddRGBPoint(86, 0.6274509803921569, 0.39215686274509803, 0.19607843137254902); 326 | color->AddRGBPoint(87, 0.9882352941176471, 0.9882352941176471, 0.9882352941176471); 327 | color->AddRGBPoint(88, 0.0784313725490196, 0.8627450980392157, 0.23529411764705882); 328 | color->AddRGBPoint(89, 0.23529411764705882, 0.8627450980392157, 0.23529411764705882); 329 | color->AddRGBPoint(90, 0.8627450980392157, 0.7058823529411765, 0.5490196078431373); 330 | color->AddRGBPoint(91, 0.8627450980392157, 0.23529411764705882, 0.0784313725490196); 331 | color->AddRGBPoint(92, 0.47058823529411764, 0.39215686274509803, 0.23529411764705882); 332 | color->AddRGBPoint(93, 0.8627450980392157, 0.0784313725490196, 0.0784313725490196); 333 | color->AddRGBPoint(94, 0.8627450980392157, 0.7058823529411765, 0.8627450980392157); 334 | color->AddRGBPoint(95, 0.23529411764705882, 0.0784313725490196, 0.8627450980392157); 335 | color->AddRGBPoint(96, 0.6274509803921569, 0.5490196078431373, 0.7058823529411765); 336 | color->AddRGBPoint(97, 0.3137254901960784, 0.0784313725490196, 0.5490196078431373); 337 | color->AddRGBPoint(98, 0.29411764705882354, 0.19607843137254902, 0.49019607843137253); 338 | color->AddRGBPoint(99, 0.0784313725490196, 0.8627450980392157, 0.6274509803921569); 339 | color->AddRGBPoint(100, 0.0784313725490196, 0.7058823529411765, 0.5490196078431373); 340 | color->AddRGBPoint(101, 0.5490196078431373, 0.8627450980392157, 0.8627450980392157); 341 | color->AddRGBPoint(102, 0.3137254901960784, 0.6274509803921569, 0.0784313725490196); 342 | color->AddRGBPoint(103, 0.39215686274509803, 0.0, 0.39215686274509803); 343 | color->AddRGBPoint(104, 0.27450980392156865, 0.27450980392156865, 0.27450980392156865); 344 | color->AddRGBPoint(105, 0.5882352941176471, 0.5882352941176471, 0.7843137254901961); 345 | color->AddRGBPoint(106, 0.3137254901960784, 0.7686274509803922, 0.3843137254901961); 346 | color->AddRGBPoint(107, 0.09803921568627451, 0.39215686274509803, 0.1568627450980392); 347 | color->AddRGBPoint(108, 0.49019607843137253, 0.39215686274509803, 0.6274509803921569); 348 | color->AddRGBPoint(109, 0.39215686274509803, 0.09803921568627451, 0.0); 349 | color->AddRGBPoint(110, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 350 | color->AddRGBPoint(111, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 351 | color->AddRGBPoint(112, 0.7058823529411765, 0.8627450980392157, 0.5490196078431373); 352 | color->AddRGBPoint(113, 0.8627450980392157, 0.23529411764705882, 0.8627450980392157); 353 | color->AddRGBPoint(114, 0.7058823529411765, 0.1568627450980392, 0.47058823529411764); 354 | color->AddRGBPoint(115, 0.5490196078431373, 0.0784313725490196, 0.5490196078431373); 355 | color->AddRGBPoint(116, 0.0784313725490196, 0.11764705882352941, 0.5490196078431373); 356 | color->AddRGBPoint(117, 0.13725490196078433, 0.29411764705882354, 0.19607843137254902); 357 | color->AddRGBPoint(118, 0.8823529411764706, 0.5490196078431373, 0.5490196078431373); 358 | color->AddRGBPoint(119, 0.7843137254901961, 0.13725490196078433, 0.29411764705882354); 359 | color->AddRGBPoint(120, 0.6274509803921569, 0.39215686274509803, 0.19607843137254902); 360 | color->AddRGBPoint(121, 0.0784313725490196, 0.8627450980392157, 0.23529411764705882); 361 | color->AddRGBPoint(122, 0.23529411764705882, 0.8627450980392157, 0.23529411764705882); 362 | color->AddRGBPoint(123, 0.8627450980392157, 0.7058823529411765, 0.5490196078431373); 363 | color->AddRGBPoint(124, 0.0784313725490196, 0.39215686274509803, 0.19607843137254902); 364 | color->AddRGBPoint(125, 0.8627450980392157, 0.23529411764705882, 0.0784313725490196); 365 | color->AddRGBPoint(126, 0.47058823529411764, 0.39215686274509803, 0.23529411764705882); 366 | color->AddRGBPoint(127, 0.8627450980392157, 0.0784313725490196, 0.0784313725490196); 367 | color->AddRGBPoint(128, 0.8627450980392157, 0.7058823529411765, 0.8627450980392157); 368 | color->AddRGBPoint(129, 0.23529411764705882, 0.0784313725490196, 0.8627450980392157); 369 | color->AddRGBPoint(130, 0.6274509803921569, 0.5490196078431373, 0.7058823529411765); 370 | color->AddRGBPoint(131, 0.3137254901960784, 0.0784313725490196, 0.5490196078431373); 371 | color->AddRGBPoint(132, 0.29411764705882354, 0.19607843137254902, 0.49019607843137253); 372 | color->AddRGBPoint(133, 0.0784313725490196, 0.8627450980392157, 0.6274509803921569); 373 | color->AddRGBPoint(134, 0.0784313725490196, 0.7058823529411765, 0.5490196078431373); 374 | color->AddRGBPoint(135, 0.5490196078431373, 0.8627450980392157, 0.8627450980392157); 375 | color->AddRGBPoint(136, 0.3137254901960784, 0.6274509803921569, 0.0784313725490196); 376 | color->AddRGBPoint(137, 0.39215686274509803, 0.0, 0.39215686274509803); 377 | color->AddRGBPoint(138, 0.27450980392156865, 0.27450980392156865, 0.27450980392156865); 378 | color->AddRGBPoint(139, 0.5882352941176471, 0.5882352941176471, 0.7843137254901961); 379 | color->AddRGBPoint(140, 0.9019607843137255, 0.9803921568627451, 0.9019607843137255); 380 | color->AddRGBPoint(141, 0.9019607843137255, 0.6078431372549019, 0.8431372549019608); 381 | color->AddRGBPoint(142, 0.5098039215686274, 0.6078431372549019, 0.37254901960784315); 382 | color->AddRGBPoint(143, 0.6078431372549019, 0.9019607843137255, 1.0); 383 | color->AddRGBPoint(144, 0.9803921568627451, 0.9411764705882353, 0.0784313725490196); 384 | color->AddRGBPoint(145, 0.13725490196078433, 0.9215686274509803, 0.6078431372549019); 385 | color->AddRGBPoint(146, 0.29411764705882354, 0.13725490196078433, 0.45098039215686275); 386 | color->AddRGBPoint(147, 0.13725490196078433, 0.7647058823529411, 0.13725490196078433); 387 | color->AddRGBPoint(148, 0.9215686274509803, 0.8823529411764706, 0.45098039215686275); 388 | color->AddRGBPoint(149, 0.8627450980392157, 0.7058823529411765, 0.803921568627451); 389 | 390 | vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New(); 391 | volumeProperty->ShadeOff(); 392 | volumeProperty->SetInterpolationTypeToLinear(); 393 | volumeProperty->SetAmbient(0.2); 394 | volumeProperty->SetDiffuse(0.9); 395 | volumeProperty->SetSpecular(0.2); 396 | volumeProperty->SetSpecularPower(20.0); 397 | 398 | volumeProperty->SetColor(color); 399 | volumeProperty->SetScalarOpacity(scalarOpacity); 400 | volumeProperty->SetGradientOpacity(gradientOpacity); 401 | volumeProperty->SetInterpolationTypeToLinear(); 402 | 403 | vtkVolume *volume = vtkVolume::New(); 404 | 405 | volume->SetMapper(mapperVolume); 406 | volume->SetProperty(volumeProperty); 407 | 408 | vtkRenderer *renderer = vtkRenderer::New(); 409 | renderer->SetBackground(0.1, 0.1, 0.2); 410 | 411 | vtkRenderWindow *renderWindow = vtkRenderWindow::New(); 412 | renderWindow->AddRenderer(renderer); 413 | renderWindow->SetSize(500, 500); 414 | renderer->AddVolume(volume); 415 | renderer->ResetCamera(); 416 | 417 | vtkInteractorStyleTrackballCamera *interactorStyle = vtkInteractorStyleTrackballCamera::New(); 418 | vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New(); 419 | renderWindowInteractor->SetInteractorStyle(interactorStyle); 420 | renderWindowInteractor->SetRenderWindow(renderWindow); 421 | 422 | renderWindow->Render(); 423 | renderWindowInteractor->Start(); 424 | 425 | 426 | return; 427 | } 428 | -------------------------------------------------------------------------------- /src/FixedPointVolumeRayCastMapperCT.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define MHA_FILETYPE 2 23 | 24 | namespace 25 | { 26 | void PrintUsage() 27 | { 28 | cout << "Usage: " << endl; 29 | cout << endl; 30 | cout << " FixedPointVolumeRayCastMapper for Bone CT Visualization " << endl; 31 | cout << endl; 32 | cout << "where options may include: " << endl; 33 | cout << endl; 34 | cout << " -DICOM " << endl; 35 | cout << " -MHA " << endl; 36 | cout << " -CT_Bone" << endl; 37 | cout << "You must use either the -DICOM option to specify the directory where" << endl; 38 | cout << "the data is located or the -MHA option to specify the path of a .mha/.mhd file." << endl; 39 | cout << endl; 40 | cout << "Example: -DICOM Head" << endl; 41 | cout << endl; 42 | } 43 | } 44 | void renderBone() 45 | { 46 | 47 | PrintUsage(); 48 | 49 | int count = 1; 50 | char *dirname = NULL; 51 | double opacityWindow = 4096; 52 | double opacityLevel = 2048; 53 | int blendType = 4; 54 | int clip = 0; 55 | double reductionFactor = 1.0; 56 | double frameRate = 10.0; 57 | char *fileName=0; 58 | int fileType=0; 59 | 60 | bool independentComponents=true; 61 | 62 | cout << "File/Directory? '-MHA / -DICOM': "; 63 | char choice[100]; 64 | cin >> choice; 65 | cout << "Enter path: "; 66 | char path[1000]; 67 | cin >> path; 68 | if (!strcmp(choice, "-DICOM")) 69 | { 70 | size_t size = strlen(path) + 1; 71 | dirname = new char[size]; 72 | snprintf(dirname, size, "%s", path); 73 | count += 2; 74 | } 75 | else if (!strcmp(choice, "-MHA")) 76 | { 77 | size_t size = strlen(path) + 1; 78 | fileName = new char[size]; 79 | fileType = MHA_FILETYPE; 80 | snprintf(fileName, size, "%s", path); 81 | count += 2; 82 | } 83 | else 84 | { 85 | cout << "Unrecognized option: " << choice << endl; 86 | cout << endl; 87 | PrintUsage(); 88 | return; 89 | } 90 | 91 | if ( !dirname && !fileName) 92 | { 93 | cout << "Error: you must specify a directory of DICOM data or a .mha!" << endl; 94 | cout << endl; 95 | PrintUsage(); 96 | return; 97 | } 98 | 99 | vtkNamedColors *colors = vtkNamedColors::New(); 100 | vtkRenderer *renderer = vtkRenderer::New(); 101 | vtkRenderWindow *renWin = vtkRenderWindow::New(); 102 | renWin->AddRenderer(renderer); 103 | 104 | 105 | vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 106 | iren->SetRenderWindow(renWin); 107 | iren->SetDesiredUpdateRate(frameRate / (1+clip) ); 108 | 109 | iren->GetInteractorStyle()->SetDefaultRenderer(renderer); 110 | 111 | vtkAlgorithm *reader=0; 112 | vtkImageData *input=0; 113 | if(dirname) 114 | { 115 | vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New(); 116 | dicomReader->SetDirectoryName(dirname); 117 | dicomReader->Update(); 118 | input=dicomReader->GetOutput(); 119 | reader=dicomReader; 120 | } 121 | else if ( fileType == MHA_FILETYPE ) 122 | { 123 | vtkMetaImageReader *metaReader = vtkMetaImageReader::New(); 124 | metaReader->SetFileName(fileName); 125 | metaReader->Update(); 126 | input=metaReader->GetOutput(); 127 | reader=metaReader; 128 | } 129 | else 130 | { 131 | cout << "Error! Not MHA!" << endl; 132 | return; 133 | } 134 | 135 | int dim[3]; 136 | input->GetDimensions(dim); 137 | if ( dim[0] < 2 || dim[1] < 2 || dim[2] < 2 ) 138 | { 139 | cout << "Error loading data!" << endl; 140 | return; 141 | } 142 | 143 | vtkVolume *volume = vtkVolume::New(); 144 | vtkFixedPointVolumeRayCastMapper *mapper = vtkFixedPointVolumeRayCastMapper::New(); 145 | 146 | mapper->SetInputConnection( reader->GetOutputPort() ); 147 | 148 | vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New(); 149 | vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New(); 150 | 151 | vtkVolumeProperty *property = vtkVolumeProperty::New(); 152 | property->SetIndependentComponents(independentComponents); 153 | property->SetColor( colorFun ); 154 | property->SetScalarOpacity( opacityFun ); 155 | property->SetInterpolationTypeToLinear(); 156 | 157 | volume->SetProperty( property ); 158 | volume->SetMapper( mapper ); 159 | 160 | colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0); 161 | colorFun->AddRGBPoint(-16, 0.73, 0.25, 0.30, 0.49, .61); 162 | colorFun->AddRGBPoint(641, .90, .82, .56, .5, 0.0); 163 | colorFun->AddRGBPoint(3071, 1, 1, 1, .5, 0.0); 164 | 165 | opacityFun->AddPoint(-3024, 0, 0.5, 0.0); 166 | opacityFun->AddPoint(-16, 0, .49, .61); 167 | opacityFun->AddPoint(641, .72, .5, 0.0); 168 | opacityFun->AddPoint(3071, .71, 0.5, 0.0); 169 | 170 | mapper->SetBlendModeToComposite(); 171 | property->ShadeOn(); 172 | property->SetAmbient(0.1); 173 | property->SetDiffuse(0.9); 174 | property->SetSpecular(0.2); 175 | property->SetSpecularPower(10.0); 176 | property->SetScalarOpacityUnitDistance(0.8919); 177 | 178 | renWin->SetSize(600,600); 179 | renWin->Render(); 180 | 181 | renderer->AddVolume( volume ); 182 | 183 | renderer->ResetCamera(); 184 | renderer->SetBackground(colors->GetColor3d("SlateGray").GetData()); 185 | 186 | renWin->Render(); 187 | 188 | iren->Start(); 189 | 190 | opacityFun->Delete(); 191 | colorFun->Delete(); 192 | property->Delete(); 193 | 194 | volume->Delete(); 195 | mapper->Delete(); 196 | reader->Delete(); 197 | renderer->Delete(); 198 | renWin->Delete(); 199 | iren->Delete(); 200 | 201 | return; 202 | } 203 | -------------------------------------------------------------------------------- /src/PROJECT.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "vtkVolumeRenderer.h" 8 | 9 | #include "FixedPointVolumeRayCastMapperCT.h" 10 | 11 | #include "ConfidenceConnected3D.h" 12 | 13 | #include "readDICOMSeries.h" 14 | 15 | #include "itkWaterShedCode.h" 16 | 17 | 18 | string s; 19 | 20 | void delay(string str) 21 | { 22 | for(int i = 0; i> "; 46 | cin>>c; 47 | if (c == 'E' || c=='e') 48 | return EXIT_SUCCESS; 49 | 50 | char dir[1000], type[100]; 51 | getchar(); 52 | switch(c) 53 | { 54 | case '1': 55 | s = "Volume Rendering for Brain Data"; 56 | delay(s); 57 | printf("Enter directory/filepath file_type[ '-FILE / -DIR' ]: "); 58 | cin>>dir>>type; 59 | renderBrain(dir,type); 60 | break; 61 | case '2': 62 | s = "Volume Rendering for CT Bone Data"; 63 | delay(s); 64 | renderBone(); 65 | break; 66 | case '3': 67 | s = "Medical Data Watershed Segmentation"; 68 | delay(s); 69 | printf("Enter file path: "); 70 | char file_name[1000]; 71 | cin>>file_name; 72 | watershedSegmentation(file_name); 73 | break; 74 | case '4': 75 | s = "DICOM file Series Viewer"; 76 | delay(s); 77 | printf("Enter directory path: "); 78 | cin>>dir; 79 | showSeries(dir); 80 | break; 81 | case '5': 82 | s = "Confidence Connected Segmentation of Brain White Matter"; 83 | delay(s); 84 | confidenceSeg(); 85 | break; 86 | } 87 | } 88 | return EXIT_SUCCESS; 89 | } 90 | -------------------------------------------------------------------------------- /src/itkWaterShedCode.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | #include "itkVectorGradientAnisotropicDiffusionImageFilter.h" 10 | #include "itkVectorGradientMagnitudeImageFilter.h" 11 | #include "itkWatershedImageFilter.h" 12 | #include "itkImageFileReader.h" 13 | #include "itkImageFileWriter.h" 14 | #include "itkVectorCastImageFilter.h" 15 | #include "itkScalarToRGBPixelFunctor.h" 16 | #include "itkGDCMImageIO.h" 17 | #include "itkMetaImageIO.h" 18 | 19 | #include "itkCommand.h" 20 | #include "itkImage.h" 21 | #include "itkVTKImageExport.h" 22 | #include "itkVTKImageImport.h" 23 | #include "itkCurvatureFlowImageFilter.h" 24 | #include "itkCastImageFilter.h" 25 | #include "itkRGBPixel.h" 26 | #include "itkImageFileReader.h" 27 | #include "itkImageFileWriter.h" 28 | #include "vtkImageData.h" 29 | 30 | #include "vtkDICOMImageReader.h" 31 | #include "vtkImageImport.h" 32 | #include "vtkImageExport.h" 33 | #include "vtkImageActor.h" 34 | #include "vtkRenderer.h" 35 | #include "vtkRenderWindow.h" 36 | #include "vtkRenderWindowInteractor.h" 37 | #include "vtkInteractorStyleImage.h" 38 | 39 | 40 | template void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer) 41 | { 42 | importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); 43 | importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); 44 | importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); 45 | importer->SetSpacingCallback(exporter->GetSpacingCallback()); 46 | importer->SetOriginCallback(exporter->GetOriginCallback()); 47 | importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); 48 | importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); 49 | importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); 50 | importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); 51 | importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); 52 | importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); 53 | importer->SetCallbackUserData(exporter->GetCallbackUserData()); 54 | } 55 | 56 | template void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer) 57 | { 58 | importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); 59 | importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); 60 | importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); 61 | importer->SetSpacingCallback(exporter->GetSpacingCallback()); 62 | importer->SetOriginCallback(exporter->GetOriginCallback()); 63 | importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); 64 | importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); 65 | importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); 66 | importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); 67 | importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); 68 | importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); 69 | importer->SetCallbackUserData(exporter->GetCallbackUserData()); 70 | } 71 | 72 | int watershedSegmentation(char *file_name) 73 | { 74 | /*if (argc < 8 ) 75 | { 76 | std::cerr << "Missing Parameters " << std::endl; 77 | std::cerr << "Usage: " << argv[0]; 78 | std::cerr << " inputImage imageType conductanceTerm diffusionIterations lowerThreshold outputScaleLevel gradientMode " << std::endl; 79 | return EXIT_FAILURE; 80 | }*/ 81 | 82 | try 83 | { 84 | 85 | char imageType[1000], conductanceTerm[1000], diffusionIterations[1000], lowerThreshold[1000], outputScaleLevel[1000], gradientMode[1000]; 86 | 87 | cout<< "Type image type- '-IMAGE'/'-DICOM':"; 88 | cin>>imageType; 89 | 90 | cout<< "Enter conductance term value: "; 91 | cin>>conductanceTerm; 92 | 93 | cout<< "Enter diffusion iterations value: "; 94 | cin>>diffusionIterations; 95 | 96 | cout<< "Enter lower threshold value: "; 97 | cin>>lowerThreshold; 98 | 99 | cout<<"Enter output scale level value: "; 100 | cin>>outputScaleLevel; 101 | 102 | cout<<"Enter gradient mode value: "; 103 | cin>> gradientMode; 104 | 105 | typedef itk::RGBPixel< unsigned char > RGBPixelType; 106 | 107 | typedef itk::Image< RGBPixelType, 2 > RGBImageType; 108 | 109 | typedef itk::Vector< float, 3 > VectorPixelType; 110 | typedef itk::Image< VectorPixelType, 2 > VectorImageType; 111 | typedef itk::Image< itk::IdentifierType, 2 > LabeledImageType; 112 | typedef itk::Image< float, 2 > ScalarImageType; 113 | 114 | typedef itk::ImageFileReader< RGBImageType > FileReaderType; 115 | 116 | typedef itk::VectorCastImageFilter< RGBImageType, VectorImageType > CastFilterType; 117 | typedef itk::VectorGradientAnisotropicDiffusionImageFilter DiffusionFilterType; 118 | typedef itk::VectorGradientMagnitudeImageFilter< VectorImageType > GradientMagnitudeFilterType; 119 | typedef itk::WatershedImageFilter< ScalarImageType > WatershedFilterType; 120 | 121 | typedef itk::GDCMImageIO ImageIOType; 122 | ImageIOType::Pointer gdcmImageIO = ImageIOType::New(); 123 | 124 | FileReaderType::Pointer reader = FileReaderType::New(); 125 | 126 | reader->SetFileName(file_name); 127 | 128 | for(int i = 0; imageType[i]!='\0'; i++) 129 | imageType[i] = toupper(imageType[i]); 130 | 131 | if(!strcmp(imageType, "-DICOM")) 132 | { 133 | reader->SetImageIO(gdcmImageIO); 134 | } 135 | try 136 | { 137 | reader->Update(); 138 | } 139 | catch (itk::ExceptionObject & e) 140 | { 141 | std::cerr << "exception in file reader " << std::endl; 142 | std::cerr << e << std::endl; 143 | return EXIT_FAILURE; 144 | } 145 | 146 | CastFilterType::Pointer caster = CastFilterType::New(); 147 | 148 | DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New(); 149 | diffusion->SetNumberOfIterations( atoi(diffusionIterations) ); 150 | diffusion->SetConductanceParameter( atof(conductanceTerm) ); 151 | diffusion->SetTimeStep(0.125); 152 | 153 | GradientMagnitudeFilterType::Pointer gradient = GradientMagnitudeFilterType::New(); 154 | gradient->SetUsePrincipleComponents(atoi(gradientMode)); 155 | 156 | WatershedFilterType::Pointer watershed = WatershedFilterType::New(); 157 | watershed->SetLevel( atof(outputScaleLevel) ); 158 | watershed->SetThreshold( atof(lowerThreshold) ); 159 | 160 | typedef itk::Functor::ScalarToRGBPixelFunctor ColorMapFunctorType; 161 | typedef itk::UnaryFunctorImageFilter ColorMapFilterType; 162 | ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New(); 163 | 164 | caster->SetInput(reader->GetOutput()); 165 | diffusion->SetInput(caster->GetOutput()); 166 | gradient->SetInput(diffusion->GetOutput()); 167 | watershed->SetInput(gradient->GetOutput()); 168 | colormapper->SetInput(watershed->GetOutput()); 169 | 170 | typedef itk::VTKImageExport< RGBImageType > ExportFilterType; // 171 | ExportFilterType::Pointer itkExporter = ExportFilterType::New(); // 172 | 173 | itkExporter->SetInput( colormapper->GetOutput() ); // 174 | 175 | vtkImageImport* vtkImporter = vtkImageImport::New(); // 176 | ConnectPipelines(itkExporter, vtkImporter); 177 | 178 | typedef itk::VTKImageImport< RGBImageType > ImportFilterType; // 179 | ImportFilterType::Pointer itkImporter = ImportFilterType::New(); // 180 | 181 | 182 | vtkImageExport* vtkExporter = vtkImageExport::New(); 183 | ConnectPipelines(vtkExporter, itkImporter); 184 | 185 | #if VTK_MAJOR_VERSION <= 5 186 | vtkExporter->SetInput( vtkImporter->GetOutput() ); 187 | #else 188 | vtkImporter->Update(); 189 | vtkExporter->SetInputData( vtkImporter->GetOutput() ); 190 | #endif 191 | 192 | vtkImageActor* actor = vtkImageActor::New(); 193 | #if VTK_MAJOR_VERSION <= 5 194 | actor->SetInput(vtkImporter->GetOutput()); 195 | #else 196 | actor->SetInputData(vtkImporter->GetOutput()); 197 | #endif 198 | 199 | vtkInteractorStyleImage * interactorStyle = vtkInteractorStyleImage::New(); 200 | 201 | vtkRenderer* renderer = vtkRenderer::New(); 202 | renderer->AddActor(actor); 203 | renderer->SetBackground(0.4392, 0.5020, 0.5647); 204 | 205 | vtkRenderWindow* renWin = vtkRenderWindow::New(); 206 | renWin->SetSize(500, 500); 207 | renWin->AddRenderer(renderer); 208 | 209 | vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New(); 210 | iren->SetRenderWindow(renWin); 211 | iren->SetInteractorStyle( interactorStyle ); 212 | 213 | 214 | renWin->Render(); 215 | iren->Start(); 216 | 217 | actor->Delete(); 218 | interactorStyle->Delete(); 219 | vtkImporter->Delete(); 220 | vtkExporter->Delete(); 221 | renWin->Delete(); 222 | renderer->Delete(); 223 | iren->Delete(); 224 | 225 | } 226 | catch (itk::ExceptionObject &e) 227 | { 228 | std::cerr << e << std::endl; 229 | return EXIT_FAILURE; 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/readDICOMSeries.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using namespace std; 18 | 19 | class StatusMessage 20 | { 21 | public: 22 | static string Format(int slice, int maxSlice) 23 | { 24 | stringstream tmp; 25 | tmp << "Slice Number " << slice + 1 << "/" << maxSlice + 1; 26 | return tmp.str(); 27 | } 28 | }; 29 | 30 | 31 | class myVtkInteractorStyleImage : public vtkInteractorStyleImage 32 | { 33 | public: 34 | static myVtkInteractorStyleImage* New(); 35 | vtkTypeMacro(myVtkInteractorStyleImage, vtkInteractorStyleImage); 36 | 37 | protected: 38 | vtkImageViewer2* _ImageViewer; 39 | vtkTextMapper* _StatusMapper; 40 | int _Slice; 41 | int _MinSlice; 42 | int _MaxSlice; 43 | 44 | public: 45 | void SetImageViewer(vtkImageViewer2* imageViewer) 46 | { 47 | _ImageViewer = imageViewer; 48 | _MinSlice = imageViewer->GetSliceMin(); 49 | _MaxSlice = imageViewer->GetSliceMax(); 50 | _Slice = _MinSlice; 51 | //cout << "Slicer: Min = " << _MinSlice << ", Max = " << _MaxSlice << std::endl; 52 | } 53 | 54 | void SetStatusMapper(vtkTextMapper* statusMapper) 55 | { 56 | _StatusMapper = statusMapper; 57 | } 58 | 59 | 60 | protected: 61 | void MoveSliceForward() 62 | { 63 | if(_Slice < _MaxSlice) 64 | { 65 | _Slice += 1; 66 | //cout << "MoveSliceForward::Slice = " << _Slice << std::endl; 67 | _ImageViewer->SetSlice(_Slice); 68 | string msg = StatusMessage::Format(_Slice, _MaxSlice); 69 | _StatusMapper->SetInput(msg.c_str()); 70 | _ImageViewer->Render(); 71 | } 72 | } 73 | 74 | void MoveSliceBackward() 75 | { 76 | if(_Slice > _MinSlice) 77 | { 78 | _Slice -= 1; 79 | //cout << "MoveSliceBackward::Slice = " << _Slice << std::endl; 80 | _ImageViewer->SetSlice(_Slice); 81 | std::string msg = StatusMessage::Format(_Slice, _MaxSlice); 82 | _StatusMapper->SetInput(msg.c_str()); 83 | _ImageViewer->Render(); 84 | } 85 | } 86 | 87 | 88 | virtual void OnKeyDown() 89 | { 90 | std::string key = this->GetInteractor()->GetKeySym(); 91 | if(key.compare("Up") == 0) 92 | { 93 | //cout << "Up arrow key was pressed." << endl; 94 | MoveSliceForward(); 95 | } 96 | else if(key.compare("Down") == 0) 97 | { 98 | //cout << "Down arrow key was pressed." << endl; 99 | MoveSliceBackward(); 100 | } 101 | // forward event 102 | vtkInteractorStyleImage::OnKeyDown(); 103 | } 104 | 105 | 106 | virtual void OnMouseWheelForward() 107 | { 108 | //std::cout << "Scrolled mouse wheel forward." << std::endl; 109 | MoveSliceForward(); 110 | 111 | } 112 | 113 | 114 | virtual void OnMouseWheelBackward() 115 | { 116 | //std::cout << "Scrolled mouse wheel backward." << std::endl; 117 | if(_Slice > _MinSlice) 118 | { 119 | MoveSliceBackward(); 120 | } 121 | 122 | } 123 | }; 124 | 125 | vtkStandardNewMacro(myVtkInteractorStyleImage); 126 | 127 | 128 | void showSeries(char *dir) 129 | { 130 | 131 | string folder = dir; 132 | 133 | vtkSmartPointer reader = vtkSmartPointer::New(); 134 | reader->SetDirectoryName(folder.c_str()); 135 | reader->Update(); 136 | 137 | vtkSmartPointer imageViewer = vtkSmartPointer::New(); 138 | imageViewer->SetInputConnection(reader->GetOutputPort()); 139 | 140 | vtkSmartPointer sliceTextProp = vtkSmartPointer::New(); 141 | sliceTextProp->SetFontFamilyToCourier(); 142 | sliceTextProp->SetFontSize(20); 143 | sliceTextProp->SetVerticalJustificationToBottom(); 144 | sliceTextProp->SetJustificationToLeft(); 145 | 146 | vtkSmartPointer sliceTextMapper = vtkSmartPointer::New(); 147 | string msg = StatusMessage::Format(imageViewer->GetSliceMin(), imageViewer->GetSliceMax()); 148 | sliceTextMapper->SetInput(msg.c_str()); 149 | sliceTextMapper->SetTextProperty(sliceTextProp); 150 | 151 | vtkSmartPointer sliceTextActor = vtkSmartPointer::New(); 152 | sliceTextActor->SetMapper(sliceTextMapper); 153 | sliceTextActor->SetPosition(15, 10); 154 | 155 | vtkSmartPointer usageTextProp = vtkSmartPointer::New(); 156 | usageTextProp->SetFontFamilyToCourier(); 157 | usageTextProp->SetFontSize(14); 158 | usageTextProp->SetVerticalJustificationToTop(); 159 | usageTextProp->SetJustificationToLeft(); 160 | 161 | vtkSmartPointer usageTextMapper = vtkSmartPointer::New(); 162 | usageTextMapper->SetInput("- Slice with mouse wheel\n or Up/Down-Key\n- Zoom with pressed right\n mouse button while dragging"); 163 | usageTextMapper->SetTextProperty(usageTextProp); 164 | 165 | vtkSmartPointer usageTextActor = vtkSmartPointer::New(); 166 | usageTextActor->SetMapper(usageTextMapper); 167 | usageTextActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedDisplay(); 168 | usageTextActor->GetPositionCoordinate()->SetValue( 0.05, 0.95); 169 | 170 | vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New(); 171 | 172 | vtkSmartPointer myInteractorStyle = vtkSmartPointer::New(); 173 | 174 | 175 | myInteractorStyle->SetImageViewer(imageViewer); 176 | myInteractorStyle->SetStatusMapper(sliceTextMapper); 177 | 178 | imageViewer->SetupInteractor(renderWindowInteractor); 179 | 180 | renderWindowInteractor->SetInteractorStyle(myInteractorStyle); 181 | 182 | imageViewer->GetRenderer()->AddActor2D(sliceTextActor); 183 | imageViewer->GetRenderer()->AddActor2D(usageTextActor); 184 | 185 | 186 | imageViewer->Render(); 187 | imageViewer->GetRenderer()->ResetCamera(); 188 | imageViewer->Render(); 189 | renderWindowInteractor->Start(); 190 | return; 191 | } 192 | -------------------------------------------------------------------------------- /src/vtkVolumeRenderer.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | void renderBrain(char *dir, char *choice) 26 | { 27 | vtkImageData *imageData = vtkImageData::New(); 28 | 29 | vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New(); 30 | 31 | vtkMetaImageReader *metaReader = vtkMetaImageReader::New(); 32 | 33 | 34 | for(int i = 0; choice[i]!='\0'; i++) 35 | choice[i] = toupper(choice[i]); 36 | 37 | if (strcmp(choice, "-DIR") == 0) 38 | { 39 | dicomReader->SetDirectoryName(dir); 40 | dicomReader->Update(); 41 | imageData->ShallowCopy(dicomReader->GetOutput()); 42 | } 43 | else if (strcmp(choice, "-FILE") == 0) 44 | { 45 | metaReader->SetFileName(dir); 46 | metaReader->Update(); 47 | imageData->ShallowCopy(metaReader->GetOutput()); 48 | } 49 | else 50 | { 51 | cout << "Error! Enter correct format" << endl; 52 | return; 53 | } 54 | 55 | vtkGPUVolumeRayCastMapper *mapperVolume = vtkGPUVolumeRayCastMapper::New(); 56 | mapperVolume->SetBlendModeToComposite(); 57 | mapperVolume->SetInputData(imageData); 58 | 59 | 60 | vtkPiecewiseFunction *gradientOpacity = vtkPiecewiseFunction::New(); 61 | 62 | gradientOpacity->AddPoint(1, 0.0); 63 | gradientOpacity->AddPoint(5, 0.1); 64 | gradientOpacity->AddPoint(100, 1.0); 65 | 66 | vtkPiecewiseFunction *scalarOpacity = vtkPiecewiseFunction::New(); 67 | 68 | 69 | scalarOpacity->AddPoint(0, 0.0); 70 | for (int i = 1; i < 150; i++) 71 | { 72 | scalarOpacity->AddPoint(i, 0.25); 73 | } 74 | 75 | vtkColorTransferFunction *color = vtkColorTransferFunction::New(); 76 | 77 | color->AddRGBPoint(0, 0.0, 0.0, 0.0); 78 | color->AddRGBPoint(1, 0.9607843137254902, 0.9607843137254902, 0.9607843137254902); 79 | color->AddRGBPoint(2, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 80 | color->AddRGBPoint(3, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 81 | color->AddRGBPoint(4, 0.8666666666666667, 0.9725490196078431, 0.6431372549019608); 82 | color->AddRGBPoint(5, 0.9019607843137255, 0.5803921568627451, 0.13333333333333333); 83 | color->AddRGBPoint(6, 0.0, 0.4627450980392157, 0.054901960784313725); 84 | color->AddRGBPoint(7, 0.47843137254901963, 0.7294117647058823, 0.8627450980392157); 85 | color->AddRGBPoint(8, 0.9254901960784314, 0.050980392156862744, 0.6901960784313725); 86 | color->AddRGBPoint(9, 0.047058823529411764, 0.18823529411764706, 1.0); 87 | color->AddRGBPoint(10, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 88 | color->AddRGBPoint(11, 0.8627450980392157, 0.8470588235294118, 0.0784313725490196); 89 | color->AddRGBPoint(12, 0.403921568627451, 1.0, 1.0); 90 | color->AddRGBPoint(13, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 91 | color->AddRGBPoint(14, 1.0, 0.6470588235294118, 0.0); 92 | color->AddRGBPoint(15, 0.6470588235294118, 0.0, 1.0); 93 | color->AddRGBPoint(16, 0.6470588235294118, 0.16470588235294117, 0.16470588235294117); 94 | color->AddRGBPoint(17, 0.2, 0.19607843137254902, 0.5294117647058824); 95 | color->AddRGBPoint(18, 0.803921568627451, 0.24313725490196078, 0.3058823529411765); 96 | color->AddRGBPoint(19, 0.9607843137254902, 0.9607843137254902, 0.9607843137254902); 97 | color->AddRGBPoint(20, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 98 | color->AddRGBPoint(21, 0.34509803921568627, 0.41568627450980394, 0.8431372549019608); 99 | color->AddRGBPoint(22, 0.8666666666666667, 0.9725490196078431, 0.6431372549019608); 100 | color->AddRGBPoint(23, 0.9019607843137255, 0.5803921568627451, 0.13333333333333333); 101 | color->AddRGBPoint(24, 0.0, 0.4627450980392157, 0.054901960784313725); 102 | color->AddRGBPoint(25, 0.47843137254901963, 0.7294117647058823, 0.8627450980392157); 103 | color->AddRGBPoint(26, 0.9254901960784314, 0.050980392156862744, 0.6901960784313725); 104 | color->AddRGBPoint(27, 0.050980392156862744, 0.18823529411764706, 1.0); 105 | color->AddRGBPoint(28, 0.8627450980392157, 0.8470588235294118, 0.0784313725490196); 106 | color->AddRGBPoint(29, 0.403921568627451, 1.0, 1.0); 107 | color->AddRGBPoint(30, 1.0, 0.6470588235294118, 0.0); 108 | color->AddRGBPoint(31, 0.6470588235294118, 0.16470588235294117, 0.16470588235294117); 109 | color->AddRGBPoint(32, 0.5294117647058824, 0.807843137254902, 0.9215686274509803); 110 | color->AddRGBPoint(33, 0.47843137254901963, 0.5294117647058824, 0.19607843137254902); 111 | color->AddRGBPoint(34, 0.47843137254901963, 0.5294117647058824, 0.19607843137254902); 112 | color->AddRGBPoint(35, 0.47058823529411764, 0.7450980392156863, 0.5882352941176471); 113 | color->AddRGBPoint(36, 1.0, 0.5803921568627451, 0.0392156862745098); 114 | color->AddRGBPoint(37, 1.0, 0.5803921568627451, 0.0392156862745098); 115 | color->AddRGBPoint(38, 0.050980392156862744, 0.18823529411764706, 1.0); 116 | color->AddRGBPoint(39, 1.0, 0.8549019607843137, 0.7254901960784313); 117 | color->AddRGBPoint(40, 0.9176470588235294, 0.6627450980392157, 0.11764705882352941); 118 | color->AddRGBPoint(41, 0.803921568627451, 0.0392156862745098, 0.49019607843137253); 119 | color->AddRGBPoint(42, 0.48627450980392156, 0.5490196078431373, 0.6980392156862745); 120 | color->AddRGBPoint(43, 0.8666666666666667, 0.8862745098039215, 0.26666666666666666); 121 | color->AddRGBPoint(44, 0.0, 0.19607843137254902, 0.5019607843137255); 122 | color->AddRGBPoint(45, 1.0, 0.8, 0.4); 123 | color->AddRGBPoint(46, 0.7843137254901961, 0.7843137254901961, 0.7843137254901961); 124 | color->AddRGBPoint(47, 0.7843137254901961, 0.7843137254901961, 0.7843137254901961); 125 | color->AddRGBPoint(48, 0.49019607843137253, 0.9803921568627451, 0.08235294117647059); 126 | color->AddRGBPoint(49, 0.49019607843137253, 0.9803921568627451, 0.08235294117647059); 127 | color->AddRGBPoint(50, 0.4, 0.6980392156862745, 1.0); 128 | color->AddRGBPoint(51, 0.4, 0.6980392156862745, 1.0); 129 | color->AddRGBPoint(52, 0.24705882352941178, 0.40784313725490196, 0.8784313725490196); 130 | color->AddRGBPoint(53, 0.24705882352941178, 0.40784313725490196, 0.8784313725490196); 131 | color->AddRGBPoint(54, 1.0, 0.09803921568627451, 0.4980392156862745); 132 | color->AddRGBPoint(55, 1.0, 0.09803921568627451, 0.4980392156862745); 133 | color->AddRGBPoint(56, 0.23529411764705882, 0.7411764705882353, 0.5098039215686274); 134 | color->AddRGBPoint(57, 0.23529411764705882, 0.7411764705882353, 0.5098039215686274); 135 | color->AddRGBPoint(58, 0.7372549019607844, 0.7098039215686275, 0.4117647058823529); 136 | color->AddRGBPoint(59, 0.7372549019607844, 0.7098039215686275, 0.4117647058823529); 137 | color->AddRGBPoint(60, 0.996078431372549, 0.8352941176470589, 0.0); 138 | color->AddRGBPoint(61, 0.996078431372549, 0.8352941176470589, 0.0); 139 | color->AddRGBPoint(62, 0.23529411764705882, 0.7058823529411765, 0.7058823529411765); 140 | color->AddRGBPoint(63, 0.23529411764705882, 0.7058823529411765, 0.7058823529411765); 141 | color->AddRGBPoint(64, 0.8, 0.4980392156862745, 0.0); 142 | color->AddRGBPoint(65, 0.8, 0.4980392156862745, 0.0); 143 | color->AddRGBPoint(66, 0.6862745098039216, 0.7607843137254902, 0.8666666666666667); 144 | color->AddRGBPoint(67, 0.6862745098039216, 0.7607843137254902, 0.8666666666666667); 145 | color->AddRGBPoint(68, 0.8823529411764706, 0.6549019607843137, 0.40784313725490196); 146 | color->AddRGBPoint(69, 0.8823529411764706, 0.6549019607843137, 0.40784313725490196); 147 | color->AddRGBPoint(70, 0.8980392156862745, 0.4980392156862745, 0.4980392156862745); 148 | color->AddRGBPoint(71, 0.8980392156862745, 0.4980392156862745, 0.4980392156862745); 149 | color->AddRGBPoint(72, 0.49019607843137253, 0.0196078431372549, 0.09803921568627451); 150 | color->AddRGBPoint(73, 0.09803921568627451, 0.39215686274509803, 0.1568627450980392); 151 | color->AddRGBPoint(74, 0.49019607843137253, 0.39215686274509803, 0.6274509803921569); 152 | color->AddRGBPoint(75, 0.39215686274509803, 0.09803921568627451, 0.0); 153 | color->AddRGBPoint(76, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 154 | color->AddRGBPoint(77, 0.8627450980392157, 0.0784313725490196, 0.0392156862745098); 155 | color->AddRGBPoint(78, 0.7058823529411765, 0.8627450980392157, 0.5490196078431373); 156 | color->AddRGBPoint(79, 0.8627450980392157, 0.23529411764705882, 0.8627450980392157); 157 | color->AddRGBPoint(80, 0.7058823529411765, 0.1568627450980392, 0.47058823529411764); 158 | color->AddRGBPoint(81, 0.5490196078431373, 0.0784313725490196, 0.5490196078431373); 159 | color->AddRGBPoint(82, 0.0784313725490196, 0.11764705882352941, 0.5490196078431373); 160 | color->AddRGBPoint(83, 0.13725490196078433, 0.29411764705882354, 0.19607843137254902); 161 | color->AddRGBPoint(84, 0.8823529411764706, 0.5490196078431373, 0.5490196078431373); 162 | color->AddRGBPoint(85, 0.7843137254901961, 0.13725490196078433, 0.29411764705882354); 163 | color->AddRGBPoint(86, 0.6274509803921569, 0.39215686274509803, 0.19607843137254902); 164 | color->AddRGBPoint(87, 0.9882352941176471, 0.9882352941176471, 0.9882352941176471); 165 | color->AddRGBPoint(88, 0.0784313725490196, 0.8627450980392157, 0.23529411764705882); 166 | color->AddRGBPoint(89, 0.23529411764705882, 0.8627450980392157, 0.23529411764705882); 167 | color->AddRGBPoint(90, 0.8627450980392157, 0.7058823529411765, 0.5490196078431373); 168 | color->AddRGBPoint(91, 0.8627450980392157, 0.23529411764705882, 0.0784313725490196); 169 | color->AddRGBPoint(92, 0.47058823529411764, 0.39215686274509803, 0.23529411764705882); 170 | color->AddRGBPoint(93, 0.8627450980392157, 0.0784313725490196, 0.0784313725490196); 171 | color->AddRGBPoint(94, 0.8627450980392157, 0.7058823529411765, 0.8627450980392157); 172 | color->AddRGBPoint(95, 0.23529411764705882, 0.0784313725490196, 0.8627450980392157); 173 | color->AddRGBPoint(96, 0.6274509803921569, 0.5490196078431373, 0.7058823529411765); 174 | color->AddRGBPoint(97, 0.3137254901960784, 0.0784313725490196, 0.5490196078431373); 175 | color->AddRGBPoint(98, 0.29411764705882354, 0.19607843137254902, 0.49019607843137253); 176 | color->AddRGBPoint(99, 0.0784313725490196, 0.8627450980392157, 0.6274509803921569); 177 | color->AddRGBPoint(100, 0.0784313725490196, 0.7058823529411765, 0.5490196078431373); 178 | color->AddRGBPoint(101, 0.5490196078431373, 0.8627450980392157, 0.8627450980392157); 179 | color->AddRGBPoint(102, 0.3137254901960784, 0.6274509803921569, 0.0784313725490196); 180 | color->AddRGBPoint(103, 0.39215686274509803, 0.0, 0.39215686274509803); 181 | color->AddRGBPoint(104, 0.27450980392156865, 0.27450980392156865, 0.27450980392156865); 182 | color->AddRGBPoint(105, 0.5882352941176471, 0.5882352941176471, 0.7843137254901961); 183 | color->AddRGBPoint(106, 0.3137254901960784, 0.7686274509803922, 0.3843137254901961); 184 | color->AddRGBPoint(107, 0.09803921568627451, 0.39215686274509803, 0.1568627450980392); 185 | color->AddRGBPoint(108, 0.49019607843137253, 0.39215686274509803, 0.6274509803921569); 186 | color->AddRGBPoint(109, 0.39215686274509803, 0.09803921568627451, 0.0); 187 | color->AddRGBPoint(110, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 188 | color->AddRGBPoint(111, 0.8627450980392157, 0.0784313725490196, 0.39215686274509803); 189 | color->AddRGBPoint(112, 0.7058823529411765, 0.8627450980392157, 0.5490196078431373); 190 | color->AddRGBPoint(113, 0.8627450980392157, 0.23529411764705882, 0.8627450980392157); 191 | color->AddRGBPoint(114, 0.7058823529411765, 0.1568627450980392, 0.47058823529411764); 192 | color->AddRGBPoint(115, 0.5490196078431373, 0.0784313725490196, 0.5490196078431373); 193 | color->AddRGBPoint(116, 0.0784313725490196, 0.11764705882352941, 0.5490196078431373); 194 | color->AddRGBPoint(117, 0.13725490196078433, 0.29411764705882354, 0.19607843137254902); 195 | color->AddRGBPoint(118, 0.8823529411764706, 0.5490196078431373, 0.5490196078431373); 196 | color->AddRGBPoint(119, 0.7843137254901961, 0.13725490196078433, 0.29411764705882354); 197 | color->AddRGBPoint(120, 0.6274509803921569, 0.39215686274509803, 0.19607843137254902); 198 | color->AddRGBPoint(121, 0.0784313725490196, 0.8627450980392157, 0.23529411764705882); 199 | color->AddRGBPoint(122, 0.23529411764705882, 0.8627450980392157, 0.23529411764705882); 200 | color->AddRGBPoint(123, 0.8627450980392157, 0.7058823529411765, 0.5490196078431373); 201 | color->AddRGBPoint(124, 0.0784313725490196, 0.39215686274509803, 0.19607843137254902); 202 | color->AddRGBPoint(125, 0.8627450980392157, 0.23529411764705882, 0.0784313725490196); 203 | color->AddRGBPoint(126, 0.47058823529411764, 0.39215686274509803, 0.23529411764705882); 204 | color->AddRGBPoint(127, 0.8627450980392157, 0.0784313725490196, 0.0784313725490196); 205 | color->AddRGBPoint(128, 0.8627450980392157, 0.7058823529411765, 0.8627450980392157); 206 | color->AddRGBPoint(129, 0.23529411764705882, 0.0784313725490196, 0.8627450980392157); 207 | color->AddRGBPoint(130, 0.6274509803921569, 0.5490196078431373, 0.7058823529411765); 208 | color->AddRGBPoint(131, 0.3137254901960784, 0.0784313725490196, 0.5490196078431373); 209 | color->AddRGBPoint(132, 0.29411764705882354, 0.19607843137254902, 0.49019607843137253); 210 | color->AddRGBPoint(133, 0.0784313725490196, 0.8627450980392157, 0.6274509803921569); 211 | color->AddRGBPoint(134, 0.0784313725490196, 0.7058823529411765, 0.5490196078431373); 212 | color->AddRGBPoint(135, 0.5490196078431373, 0.8627450980392157, 0.8627450980392157); 213 | color->AddRGBPoint(136, 0.3137254901960784, 0.6274509803921569, 0.0784313725490196); 214 | color->AddRGBPoint(137, 0.39215686274509803, 0.0, 0.39215686274509803); 215 | color->AddRGBPoint(138, 0.27450980392156865, 0.27450980392156865, 0.27450980392156865); 216 | color->AddRGBPoint(139, 0.5882352941176471, 0.5882352941176471, 0.7843137254901961); 217 | color->AddRGBPoint(140, 0.9019607843137255, 0.9803921568627451, 0.9019607843137255); 218 | color->AddRGBPoint(141, 0.9019607843137255, 0.6078431372549019, 0.8431372549019608); 219 | color->AddRGBPoint(142, 0.5098039215686274, 0.6078431372549019, 0.37254901960784315); 220 | color->AddRGBPoint(143, 0.6078431372549019, 0.9019607843137255, 1.0); 221 | color->AddRGBPoint(144, 0.9803921568627451, 0.9411764705882353, 0.0784313725490196); 222 | color->AddRGBPoint(145, 0.13725490196078433, 0.9215686274509803, 0.6078431372549019); 223 | color->AddRGBPoint(146, 0.29411764705882354, 0.13725490196078433, 0.45098039215686275); 224 | color->AddRGBPoint(147, 0.13725490196078433, 0.7647058823529411, 0.13725490196078433); 225 | color->AddRGBPoint(148, 0.9215686274509803, 0.8823529411764706, 0.45098039215686275); 226 | color->AddRGBPoint(149, 0.8627450980392157, 0.7058823529411765, 0.803921568627451); 227 | 228 | vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New(); 229 | volumeProperty->ShadeOff(); 230 | volumeProperty->SetInterpolationTypeToLinear(); 231 | volumeProperty->SetAmbient(0.2); 232 | volumeProperty->SetDiffuse(0.9); 233 | volumeProperty->SetSpecular(0.2); 234 | volumeProperty->SetSpecularPower(20.0); 235 | 236 | volumeProperty->SetColor(color); 237 | volumeProperty->SetScalarOpacity(scalarOpacity); 238 | volumeProperty->SetGradientOpacity(gradientOpacity); 239 | volumeProperty->SetInterpolationTypeToLinear(); 240 | 241 | vtkVolume *volume = vtkVolume::New(); 242 | volume->SetMapper(mapperVolume); 243 | volume->SetProperty(volumeProperty); 244 | 245 | vtkRenderer *renderer = vtkRenderer::New(); 246 | renderer->SetBackground(0.1, 0.1, 0.2); 247 | 248 | vtkRenderWindow *renderWindow = vtkRenderWindow::New(); 249 | renderWindow->AddRenderer(renderer); 250 | renderWindow->SetSize(500, 500); 251 | renderer->AddVolume(volume); 252 | renderer->ResetCamera(); 253 | 254 | vtkInteractorStyleTrackballCamera *interactorStyle = vtkInteractorStyleTrackballCamera::New(); 255 | vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New(); 256 | renderWindowInteractor->SetInteractorStyle(interactorStyle); 257 | renderWindowInteractor->SetRenderWindow(renderWindow); 258 | 259 | renderWindow->Render(); 260 | renderWindowInteractor->Start(); 261 | 262 | } 263 | --------------------------------------------------------------------------------