File: vtkDICOMAlgorithm.cxx

package info (click to toggle)
vtk-dicom 0.8.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,176 kB
  • sloc: cpp: 113,811; python: 2,041; makefile: 43; tcl: 10
file content (174 lines) | stat: -rw-r--r-- 5,775 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*=========================================================================

  Program: DICOM for VTK

  Copyright (c) 2012-2024 David Gobbi
  All rights reserved.
  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkDICOMAlgorithm.h"
#include "vtkDICOMMetaData.h"

#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformationDataObjectKey.h"
#include "vtkInformationDoubleVectorKey.h"
#include "vtkImageData.h"
#include "vtkInformationVector.h"
#include "vtkInformation.h"
#include "vtkMatrix4x4.h"
#include "vtkAlgorithmOutput.h"
#include "vtkTrivialProducer.h"
#include "vtkSmartPointer.h"
#include "vtkVersion.h"

vtkStandardNewMacro(vtkDICOMAlgorithm);

vtkInformationKeyMacro(vtkDICOMAlgorithm, PATIENT_MATRIX, DoubleVector);
vtkInformationKeyMacro(vtkDICOMAlgorithm, META_DATA, DataObject);

//----------------------------------------------------------------------------
vtkDICOMAlgorithm::vtkDICOMAlgorithm()
{
}

//----------------------------------------------------------------------------
vtkDICOMAlgorithm::~vtkDICOMAlgorithm()
{
}

//----------------------------------------------------------------------------
void vtkDICOMAlgorithm::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
}

//----------------------------------------------------------------------------
vtkInformation *vtkDICOMAlgorithm::GetMetaDataInformation(
  vtkInformationVector** inputVector, int inputPort, int inputConnection)
{
  vtkInformation *inInfo =
    inputVector[inputPort]->GetInformationObject(inputConnection);

  // If SetInputConnection was used, meta data is attached to inInfo
  vtkInformation *metaInfo = inInfo;

  // If SetInputData was used, the meta data is attached to the data
  vtkAlgorithmOutput *sourceConnection = this->GetInputConnection(0, 0);
  if (sourceConnection)
  {
    // SetInputData causes a vtkTrivialProducer to be used
    vtkAlgorithm *producer = sourceConnection->GetProducer();
    if (producer && vtkTrivialProducer::SafeDownCast(producer))
    {
      vtkDataObject *inputData = producer->GetOutputDataObject(0);
      if (inputData)
      {
        metaInfo = inputData->GetInformation();
      }
    }
  }

  return metaInfo;
}

//----------------------------------------------------------------------------
void vtkDICOMAlgorithm::CopyMetaDataToOutputInformation(
  vtkInformationVector** inputVector, int inputPort, int inputConnection,
  vtkInformationVector* outputVector, int outputPort)
{
  // If SetInputConnection was used, meta data is attached to inInfo
  vtkInformation *metaInfo = this->GetMetaDataInformation(
    inputVector, inputPort, inputConnection);

  // Set the output port to copy the meta data to
  int firstPort = outputPort;
  int lastPort = outputPort;
  if (outputPort < 0)
  {
    firstPort = 0;
    lastPort = this->GetNumberOfOutputPorts() - 1;
  }

  // Copy the meta data downstream
  for (int port = firstPort; port <= lastPort; port++)
  {
    vtkInformation *outInfo = outputVector->GetInformationObject(port);
    // Matrix is stored as a vector of 16 doubles
    outInfo->CopyEntry(metaInfo, PATIENT_MATRIX());

    // MetaData object must be shallow-copied
    vtkDICOMMetaData *meta = vtkDICOMMetaData::SafeDownCast(
      metaInfo->Get(META_DATA()));
    if (meta)
    {
      vtkSmartPointer<vtkDICOMMetaData> outMeta =
        vtkSmartPointer<vtkDICOMMetaData>::New();
      outMeta->ShallowCopy(meta);
      outInfo->Set(META_DATA(), outMeta);
    }
  }
}

//----------------------------------------------------------------------------
void vtkDICOMAlgorithm::CopyMetaDataToOutputData(
  vtkInformation *info, vtkDataObject *data)
{
  vtkInformation *dataInfo = data->GetInformation();
  dataInfo->CopyEntry(info, META_DATA());
  dataInfo->CopyEntry(info, PATIENT_MATRIX());
}

//----------------------------------------------------------------------------
int vtkDICOMAlgorithm::RequestInformation(
  vtkInformation* request,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  // Copy the meta data to the output information
  if (this->GetNumberOfInputPorts() > 0 &&
      this->GetNumberOfInputConnections(0) > 0)
  {
    this->CopyMetaDataToOutputInformation(
      inputVector, 0, 0, outputVector, -1);
  }

  return this->Superclass::RequestInformation(
    request, inputVector, outputVector);
}

//----------------------------------------------------------------------------
int vtkDICOMAlgorithm::RequestData(
  vtkInformation* request,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  // Copy the meta data downstream
  int numPorts = this->GetNumberOfOutputPorts();
  for (int port = 0; port < numPorts; port++)
  {
    vtkInformation *outInfo = outputVector->GetInformationObject(port);
    vtkImageData *outData = vtkImageData::SafeDownCast(
      outInfo->Get(vtkDataObject::DATA_OBJECT()));
    if (outData)
    {
      this->CopyMetaDataToOutputData(outInfo, outData);
    }
  }

  return this->Superclass::RequestData(request, inputVector, outputVector);
}

//----------------------------------------------------------------------------
void vtkDICOMAlgorithm::ThreadedRequestData(
  vtkInformation *, vtkInformationVector **, vtkInformationVector *,
  vtkImageData ***, vtkImageData **, int [6], int)
{
  vtkWarningMacro("ThreadedRequestData: This method was not implemented in "
                  << this->GetClassName());
}