6
* Copyright 2008-14 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
13
#include "iannotator.h"
14
#include <api/icontexto.h>
15
#include <api/iwidgetsrenderer.h>
16
#include <api/iwidgetsmanager.h>
17
#include <api/ivista.h>
18
#include <api/istudycontext.h>
19
#include <main/entorno.h>
20
#include <vtkginkgoimageviewer.h>
21
#include <api/dicom/dcmdictionary.h>
22
#include <api/internationalization/internationalization.h>
23
#include <vtkRenderWindow.h>
24
#include <vtkImageData.h>
26
GNC::GCS::IAnnotator::IAnnotator(GNC::GCS::IVista *pView): m_pView(pView)
30
GNC::GCS::IAnnotator::~IAnnotator()
34
std::string GNC::GCS::IAnnotator::GetAnnotationValue(GNC::GCS::Contexto3D* c, const std::string& key)
36
if (key == "${NEWLINE}") {
38
} else if (key =="${GINKGO.VERSION.FULLTEXT}") {
39
return GNC::Entorno::Instance()->GetGinkgoVersionString();
40
} else if (key =="${GINKGO.ARCH}") {
41
if (sizeof(void*) == 4) {
47
} else if (key == "${VOLUME.IDX}") {
48
if (m_pView != NULL && m_pView != NULL && m_pView->GetEstudio().IsValid()) {
49
std::ostringstream ostr;
50
ostr << m_pView->GetEstudio()->ActiveFileIndex + 1;
53
} else if (key == "${SLICE.WIDTH}") {
54
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
56
c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
57
std::ostringstream ostr;
61
} else if (key == "${SLICE.HEIGHT}") {
62
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
64
c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
65
std::ostringstream ostr;
69
} else if (key == "${SLICE.WL.FULLTEXT}") {
70
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
71
std::ostringstream ostr;
73
ostr << std::setiosflags(ios::fixed) << std::setprecision(2);
74
ostr << c->GetRenderer()->m_pImageViewer->GetWindow() << "/" << c->GetRenderer()->m_pImageViewer->GetLevel();
77
} else if (key == "${SLICE.IDX}") {
78
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
79
std::ostringstream ostr;
80
ostr << c->GetRenderer()->m_pImageViewer->GetTindex() + 1;
83
} else if (key == "${SLICE.COUNT}") {
84
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
86
c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
87
std::ostringstream ostr;
91
} else if (key == "${SLICE.IDX.FULLTEXT}") {
92
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL && m_pView != NULL && m_pView->GetEstudio().IsValid()) {
94
c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
95
std::ostringstream ostr;
96
ostr << _Std("Slice") << ": " << c->GetRenderer()->m_pImageViewer->GetTindex() + 1 << " " << _Std("of") << " " << dims[2] << std::endl << _Std("Volume") << ": " << m_pView->GetEstudio()->ActiveFileIndex + 1;
99
} else if (key == "${SLICE.VOXEL.SIZE}") {
100
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL && m_pView != NULL && m_pView->GetEstudio().IsValid()) {
102
bool hasSpacing = m_pView->GetEstudio()->GetSpacingActive(spacing[0], spacing[1], spacing[2]);
103
std::ostringstream ostr;
105
ostr << _Std("Voxel:") << spacing[0] << "x" << spacing[1] << " mm.";
108
ostr << _Std("Image without metric information");
112
} else if (key == "${SLICE.THICKNESS}") {
113
return GetTagValue(c, GKDCM_SliceThickness);
114
} else if (key == "${SLICE.THICKNESS.FULLTEXT}") {
115
std::string thick = GetTagValue(c, GKDCM_SliceThickness);
117
std::ostringstream ostr;
118
ostr << std::setiosflags(ios::fixed) << std::setprecision(3);
119
ostr << _Std("Slice thickness") << ": " << GetTagValue(c, GKDCM_SliceThickness) << " mm.";
122
} else if (key == "${SLICE.LOCATION}") {
123
return GetTagValue(c, GKDCM_SliceLocation);
124
} else if (key == "${SLICE.LOCATION.FULLTEXT}") {
125
std::string loc = GetTagValue(c, GKDCM_SliceLocation);
127
std::ostringstream ostr;
128
ostr << std::setiosflags(ios::fixed) << std::setprecision(3);
129
ostr << _Std("Slice location") << ": " << loc;
132
} else if (key == "${VIEW.SCALE}") {
133
if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
134
double ppmm = (c->GetRenderer()->m_pImageViewer->GetRenderWindow()->GetDPI() / 25.4); // pixels per mm
135
double mmpp = 1.0 / ppmm; // mm per pixel
137
c->GetRenderer()->m_pImageViewer->GetSpacing(spacing);
138
double onePixelHeight = c->GetRenderer()->m_pImageViewer->GetZoomFactor();
139
std::ostringstream ostr;
140
ostr << _Std("Scale") << " 1:" << ( (spacing[1] * mmpp) / onePixelHeight);
143
} else if (key == "${SLICE.LATERALITY}") {
144
std::string lat = GetTagValue(c, GKDCM_ImageLaterality);
146
std::ostringstream ostr;
148
ostr << _Std("Right") << ";" ;
150
ostr << _Std("Left") << ";";
159
std::string GNC::GCS::IAnnotator::GetTagValue(GNC::GCS::Contexto3D* /*c*/, const std::string& key, const std::string& defValue)
161
if (m_pView != NULL && m_pView->GetEstudio().IsValid()) {
163
if (m_pView->GetEstudio()->GetTagActiveImage(key, value) && !value.empty()) {
170
std::string GNC::GCS::IAnnotator::GetPositionAnnotation(GNC::GCS::Contexto3D* c, const GNC::GCS::Vector3D& wP)
172
if (c->pRenderer == NULL || c->pRenderer->m_pImageViewer == NULL) {
175
std::ostringstream os;
176
os.setf(ios::floatfield, ios::fixed );
180
//double zpos = SeriesViewer->GetPipeline()->GetCurrentSliceIndex();
182
double ip[3] = {0,0,0};
183
c->pRenderer->m_pImageViewer->Proyect2D(wP.v, ip);
184
int pp[3] = {0, 0, 0};
187
c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
189
os << _Std("Position:") << " W:(" << wP.x << ", " << wP.y << "," << wP.z << "); I:(" << ip[0] << ", " << ip[1] << ", " << ip[2] << ")";
191
//corregir de convencion DICOM a convenciotk
193
c->GetRenderer()->m_pImageViewer->CoordenadasImagenACoordenadasPixel(ip, pp);
194
if (pp[0]>=0 && pp[0] < dims[0] && pp[1]>=0 && pp[1] < dims[1] && pp[2] >=0 && pp[2] < dims[2]) {
195
const vtkSmartPointer<vtkImageData>& pImg = c->GetRenderer()->m_pImageViewer->GetDataObject();
196
if (pImg == NULL || pImg->GetNumberOfPoints() == 0)
200
void *scalar = pImg->GetScalarPointer( (int)pp[0], (int)pp[1], (int)pp[2] );
207
for(int i = 0; i< c->GetRenderer()->m_pImageViewer->GetNumberOfComponents(); i++) {
208
switch (c->GetRenderer()->m_pImageViewer->GetInput()->GetScalarType()) {
210
value = (((double*)scalar)[i]);
213
value = (double) (((float*)scalar)[i]);
215
case VTK_UNSIGNED_LONG:
216
value = (double) (((unsigned long*)scalar)[i]);
219
value = (double) (((long*)scalar)[i]);
221
case VTK_UNSIGNED_INT:
222
value = (double) (((unsigned int*)scalar)[i]);
225
value = (double) (((int*)scalar)[i]);
227
case VTK_UNSIGNED_SHORT:
228
value = (double) (((unsigned short*)scalar)[i]);
231
value = (double) (((short*)scalar)[i]);
233
case VTK_UNSIGNED_CHAR:
234
value = (double) (((unsigned char*)scalar)[i]);
237
value = (double) (((char*)scalar)[i]);
242
os << " " << _Std("Value:") << value;
b'\\ No newline at end of file'