~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/api/iannotator.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2014-01-09 07:37:09 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20140109073709-rpuh5x3p3finvtze
Tags: 3.6.0.1228.33+dfsg-1
New upstream release [December 2013]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: ianotador.h $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-14 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 */
 
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>
 
25
 
 
26
GNC::GCS::IAnnotator::IAnnotator(GNC::GCS::IVista *pView): m_pView(pView)
 
27
{
 
28
}
 
29
 
 
30
GNC::GCS::IAnnotator::~IAnnotator()
 
31
{
 
32
}
 
33
 
 
34
std::string GNC::GCS::IAnnotator::GetAnnotationValue(GNC::GCS::Contexto3D* c, const std::string& key)
 
35
{
 
36
        if (key == "${NEWLINE}") {
 
37
                return "\n";
 
38
        } else if (key =="${GINKGO.VERSION.FULLTEXT}") {
 
39
                return GNC::Entorno::Instance()->GetGinkgoVersionString();
 
40
        } else if (key =="${GINKGO.ARCH}") {
 
41
                if (sizeof(void*) == 4) {
 
42
                        return "32 bits";
 
43
                }
 
44
                else {
 
45
                        return "64 bits";
 
46
                }
 
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;
 
51
                        return ostr.str();
 
52
                }
 
53
        } else if (key == "${SLICE.WIDTH}") {
 
54
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
 
55
                        int dims[3];
 
56
                        c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
 
57
                        std::ostringstream ostr;
 
58
                        ostr << dims[0];
 
59
                        return ostr.str();
 
60
                }
 
61
        } else if (key == "${SLICE.HEIGHT}") {
 
62
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
 
63
                        int dims[3];
 
64
                        c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
 
65
                        std::ostringstream ostr;
 
66
                        ostr << dims[1];
 
67
                        return ostr.str();
 
68
                }
 
69
        } else if (key == "${SLICE.WL.FULLTEXT}") {
 
70
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
 
71
                        std::ostringstream ostr;
 
72
                        ostr << "WL: ";
 
73
                        ostr << std::setiosflags(ios::fixed) << std::setprecision(2);
 
74
                        ostr << c->GetRenderer()->m_pImageViewer->GetWindow() << "/" << c->GetRenderer()->m_pImageViewer->GetLevel();
 
75
                        return ostr.str();
 
76
                }
 
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;
 
81
                        return ostr.str();
 
82
                }
 
83
        } else if (key == "${SLICE.COUNT}") {
 
84
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL) {
 
85
                        int dims[3];
 
86
                        c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
 
87
                        std::ostringstream ostr;
 
88
                        ostr << dims[2];
 
89
                        return ostr.str();
 
90
                }
 
91
        } else if (key == "${SLICE.IDX.FULLTEXT}") {
 
92
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL && m_pView != NULL && m_pView->GetEstudio().IsValid()) {
 
93
                        int dims[3];
 
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;
 
97
                        return ostr.str();
 
98
                }
 
99
        } else if (key == "${SLICE.VOXEL.SIZE}") {
 
100
                if (c->GetRenderer() != NULL && c->GetRenderer()->m_pImageViewer != NULL && m_pView != NULL && m_pView->GetEstudio().IsValid()) {
 
101
                        double spacing[3];
 
102
                        bool hasSpacing = m_pView->GetEstudio()->GetSpacingActive(spacing[0], spacing[1], spacing[2]);
 
103
                        std::ostringstream ostr;
 
104
                        if (hasSpacing) {
 
105
                                ostr << _Std("Voxel:") << spacing[0] << "x" << spacing[1] << " mm.";
 
106
                        }
 
107
                        else {
 
108
                                ostr << _Std("Image without metric information");
 
109
                        }
 
110
                        return ostr.str();
 
111
                }
 
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);
 
116
                if(thick != "") {
 
117
                        std::ostringstream ostr;
 
118
                        ostr << std::setiosflags(ios::fixed) << std::setprecision(3);
 
119
                        ostr << _Std("Slice thickness") << ": " << GetTagValue(c, GKDCM_SliceThickness) << " mm.";
 
120
                        return ostr.str();
 
121
                }
 
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);
 
126
                if(loc != "") {
 
127
                        std::ostringstream ostr;
 
128
                        ostr << std::setiosflags(ios::fixed) << std::setprecision(3);
 
129
                        ostr << _Std("Slice location") << ": " << loc;
 
130
                        return ostr.str();
 
131
                }
 
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
 
136
                        double spacing[3];
 
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);
 
141
                        return ostr.str();
 
142
                }
 
143
        } else if (key == "${SLICE.LATERALITY}") {
 
144
                std::string lat = GetTagValue(c, GKDCM_ImageLaterality);
 
145
                if(lat != "") {
 
146
                        std::ostringstream ostr;
 
147
                        if(lat=="R"){
 
148
                                ostr << _Std("Right") << ";" ;
 
149
                        }else if(lat=="L"){
 
150
                                ostr << _Std("Left") << ";";
 
151
                        }
 
152
                        return ostr.str();
 
153
                }
 
154
        }
 
155
        
 
156
        return "";
 
157
}
 
158
 
 
159
std::string GNC::GCS::IAnnotator::GetTagValue(GNC::GCS::Contexto3D* /*c*/, const std::string& key, const std::string& defValue)
 
160
{
 
161
        if (m_pView != NULL && m_pView->GetEstudio().IsValid()) {
 
162
                std::string value;
 
163
                if (m_pView->GetEstudio()->GetTagActiveImage(key, value) && !value.empty()) {
 
164
                        return value;
 
165
                } 
 
166
        } 
 
167
        return defValue;
 
168
}
 
169
 
 
170
std::string GNC::GCS::IAnnotator::GetPositionAnnotation(GNC::GCS::Contexto3D* c, const GNC::GCS::Vector3D& wP)
 
171
{
 
172
        if (c->pRenderer == NULL || c->pRenderer->m_pImageViewer == NULL) {
 
173
                return "";
 
174
        }
 
175
        std::ostringstream os;
 
176
        os.setf(ios::floatfield, ios::fixed );
 
177
        os.precision(2);
 
178
        os.fill('0');
 
179
 
 
180
        //double zpos = SeriesViewer->GetPipeline()->GetCurrentSliceIndex();
 
181
 
 
182
        double ip[3] = {0,0,0};
 
183
        c->pRenderer->m_pImageViewer->Proyect2D(wP.v, ip);
 
184
        int pp[3] = {0, 0, 0};
 
185
        int dims[3];
 
186
 
 
187
        c->GetRenderer()->m_pImageViewer->GetDimensions(dims);
 
188
                                
 
189
        os << _Std("Position:") << " W:(" << wP.x << ", " << wP.y << "," << wP.z << "); I:(" << ip[0] << ", " << ip[1] << ", " << ip[2] << ")";
 
190
 
 
191
        //corregir de convencion DICOM a convenciotk
 
192
 
 
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)
 
197
                {
 
198
                        return "";
 
199
                }
 
200
                void *scalar = pImg->GetScalarPointer( (int)pp[0], (int)pp[1], (int)pp[2] );            
 
201
 
 
202
                if( scalar ) {
 
203
                        
 
204
                        bool primero = true;
 
205
                        double value = 0.0f;
 
206
 
 
207
                        for(int i = 0; i< c->GetRenderer()->m_pImageViewer->GetNumberOfComponents(); i++) {                             
 
208
                                switch (c->GetRenderer()->m_pImageViewer->GetInput()->GetScalarType()) {
 
209
                                        case VTK_DOUBLE:
 
210
                                                value = (((double*)scalar)[i]);
 
211
                                                break;
 
212
                                        case VTK_FLOAT:
 
213
                                                value = (double) (((float*)scalar)[i]);
 
214
                                                break;
 
215
                                        case VTK_UNSIGNED_LONG:
 
216
                                                value = (double) (((unsigned long*)scalar)[i]);
 
217
                                                break;
 
218
                                        case VTK_LONG:
 
219
                                                value = (double) (((long*)scalar)[i]);
 
220
                                                break;
 
221
                                        case VTK_UNSIGNED_INT:
 
222
                                                value = (double) (((unsigned int*)scalar)[i]);
 
223
                                                break;
 
224
                                        case VTK_INT:
 
225
                                                value = (double) (((int*)scalar)[i]);
 
226
                                                break;
 
227
                                        case VTK_UNSIGNED_SHORT:
 
228
                                                value = (double) (((unsigned short*)scalar)[i]);
 
229
                                                break;
 
230
                                        case VTK_SHORT:
 
231
                                                value = (double) (((short*)scalar)[i]);
 
232
                                                break;
 
233
                                        case VTK_UNSIGNED_CHAR:
 
234
                                                value = (double) (((unsigned char*)scalar)[i]);
 
235
                                                break;
 
236
                                        case VTK_CHAR:
 
237
                                                value = (double) (((char*)scalar)[i]);
 
238
                                                break;
 
239
                                }
 
240
 
 
241
                                if(primero) {
 
242
                                        os << " " << _Std("Value:") << value;
 
243
                                } else {
 
244
                                        os << "," << value;
 
245
                                }
 
246
                                primero = false;
 
247
                        }
 
248
                }
 
249
        }
 
250
 
 
251
        return os.str();
 
252
}
 
 
b'\\ No newline at end of file'