ivustcdemo.cpp 8.72 KB
Newer Older
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
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "ivustcdemo.h"

27
#include "tgt/filesystem.h"
28
#include "core/datastructures/imagedata.h"
29
#include "core/datastructures/genericimagerepresentationlocal.h"
30

31
#include "core/classification/simpletransferfunction.h"
32

33
#include "modules/ivus_tc/processors/ivustcsliceextractor.h"
34
#include "modules/ivus_tc/processors/ivustcraycaster.h"
35

36
37
38
39
namespace campvis {

    IvusTcDemo::IvusTcDemo(DataContainer* dc)
        : AutoEvaluationPipeline(dc)
40
41
        , p_sourceDirectory("SoruceDirectory", "Source Directory", "D:/Medical Data/IVUS/H52 LAD1", StringProperty::DIRECTORY)
        , p_readImagesButton("ReadImagesButton", "Read Images")
42
        , p_predicateHistogram("PredicateHistogram", "Voxel Predicate Selection")
43
44
        , _lsp()
        , _imageReader(&_canvasSize)
45
        , _ve(&_canvasSize, new IvusTcSliceExtractor(nullptr), new IvusTcRaycaster(nullptr))
46
    {
47
48
49
        // Use AbstractPipeline overload to avoid automatic evaluation of _imageReader processor
//        AbstractPipeline::addProcessor(&_imageReader);

50
51
52
        addProcessor(&_lsp);
        addProcessor(&_ve);

53
54
55
        addProperty(p_sourceDirectory);
        addProperty(p_readImagesButton);

56
        addEventListenerToBack(&_ve);
57
58

        p_predicateHistogram.getPredicateHistogram()->setPredicateFunctionArgumentString("in float ivus, in float cm, in vec4 tc, in float plaque");
59
60
61
62
63
64
65
    }

    IvusTcDemo::~IvusTcDemo() {
    }

    void IvusTcDemo::init() {
        AutoEvaluationPipeline::init();
66
67
        _imageReader.init();
        p_readImagesButton.s_clicked.connect(this, &IvusTcDemo::readAndProcessImages);
68
69

        _ve.p_inputVolume.setValue("image.ivus");
70
        _ve.p_outputImage.setValue("combine");
71
72
        _ve.getVolumeRenderer()->getRaycastingProcessor()->p_samplingRate.setValue(1.f);

73
74
75
        _renderTargetID.setValue("combine");
        
        _imageReader.p_fileExtension.setValue("bmp");
76
        _imageReader.p_imageSpacing.setValue(tgt::vec3(.1f, .1f, .75f));
77

78
        // initialize predicates with default config
79
        PointPredicateHistogramProperty* php = &p_predicateHistogram;
80
81
82
83
84
        if (php != nullptr) {
            PointPredicateHistogram* histogram = php->getPredicateHistogram();

            AbstractPointPredicate* vpToAdd = 0;

85
86
87
88
//             vpToAdd = new RangePointPredicate("cm", "ConfidenceMap", "Confidence");
//             static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.25f, 1.f));
//             histogram->addPredicate(vpToAdd);
// 
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
            vpToAdd = new RangePointPredicate("tc.r", "Calcified", "Calcified Tissue");
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.15f, 1.f));
            vpToAdd->p_color.setValue(tgt::vec2(0.f, 1.f));
            histogram->addPredicate(vpToAdd);

            vpToAdd = new RangePointPredicate("tc.g", "Fibrotic", "Fibrotic Tissue");
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.15f, 1.f));
            vpToAdd->p_color.setValue(tgt::vec2(0.2f, 1.f));
            histogram->addPredicate(vpToAdd);

            vpToAdd = new RangePointPredicate("tc.b", "Lipidic", "Lipidic Tissue");
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.15f, 1.f));
            vpToAdd->p_color.setValue(tgt::vec2(0.4f, 1.f));
            histogram->addPredicate(vpToAdd);

            vpToAdd = new RangePointPredicate("tc.a", "Necrotic", "Necrotic Tissue");
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.15f, 1.f));
            vpToAdd->p_color.setValue(tgt::vec2(0.6f, 1.f));
            histogram->addPredicate(vpToAdd);

            vpToAdd = new RangePointPredicate("plaque", "Plaque", "Plaque Mask");
            static_cast<RangePointPredicate*>(vpToAdd)->p_range.setValue(tgt::vec2(0.5f, 1.f));
            vpToAdd->p_color.setValue(tgt::vec2(0.8f, 1.f));
            histogram->addPredicate(vpToAdd);

            histogram->resetPredicates(false);
            addProperty(*php);
116
117
118

            php->addSharedProperty(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::PredicateHistogram"));
            php->addSharedProperty(_ve.getNestedProperty("SliceExtractorProperties::PredicateHistogram"));
119
120
        }

121
122
123
124
125
        SimpleTransferFunction* stf = new SimpleTransferFunction(128, tgt::vec2(.1f, 1.f));
        stf->setLeftColor(tgt::vec4(0.f));
        stf->setRightColor(tgt::vec4(255.f));
        static_cast<TransferFunctionProperty*>(_ve.getNestedProperty("VolumeRendererProperties::RaycasterProps::TransferFunction"))->replaceTF(stf);

126
127
128
    }

    void IvusTcDemo::deinit() {
129
130
        _imageReader.deinit();
        p_readImagesButton.s_clicked.disconnect(this);
131
132
133
        AutoEvaluationPipeline::deinit();
    }

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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    void IvusTcDemo::readAndProcessImages() {
        std::string baseDir = tgt::FileSystem::cleanupPath(p_sourceDirectory.getValue());

        std::string ivusDir = baseDir + "/IVUS";
        std::string cmDir = baseDir + "/Confidence_Map";
        std::string calcifiedDir = baseDir + "/Calcified_Map";
        std::string fibroticDir = baseDir + "/Fibrotic_Map";
        std::string lipidicDir = baseDir + "/Lipidic_Map";
        std::string necroticDir = baseDir + "/Necrotic_Map";
        std::string plaqueDir = baseDir + "/Plaque_Mask";

        // read images
        readImage(ivusDir, "image.ivus");
        readImage(cmDir, "image.cm");

        readImage(calcifiedDir, "image.calcified");
        readImage(fibroticDir , "image.fibrotic" );
        readImage(lipidicDir  , "image.lipidic"  );
        readImage(necroticDir , "image.necrotic" );

        readImage(plaqueDir, "image.plaque");

        // fuse TC maps into single 4-channel image
        typedef uint8_t ivus_t;
        GenericImageRepresentationLocal<ivus_t, 1>::ScopedRepresentation calcifiedRep(getDataContainer(), "image.calcified");
        GenericImageRepresentationLocal<ivus_t, 1>::ScopedRepresentation fibroticRep(getDataContainer(), "image.fibrotic");
        GenericImageRepresentationLocal<ivus_t, 1>::ScopedRepresentation lipidicRep(getDataContainer(), "image.lipidic");
        GenericImageRepresentationLocal<ivus_t, 1>::ScopedRepresentation necroticRep(getDataContainer(), "image.necrotic");

        if (   (calcifiedRep && fibroticRep && lipidicRep && necroticRep) 
            && (calcifiedRep->getSize() == fibroticRep->getSize() && fibroticRep->getSize() == lipidicRep->getSize() && lipidicRep->getSize() == necroticRep->getSize())) {
            ImageData* id = new ImageData(3, calcifiedRep->getSize(), 4);
            tgt::Vector4<ivus_t>* data = new tgt::Vector4<ivus_t>[tgt::hmul(calcifiedRep->getSize())];

            for (size_t i = 0; i < calcifiedRep->getNumElements(); ++i) {
                data[i] = tgt::Vector4<ivus_t>(calcifiedRep->getElement(i), fibroticRep->getElement(i), lipidicRep->getElement(i), necroticRep->getElement(i));
            }

            GenericImageRepresentationLocal<ivus_t, 4>::create(id, data);
            id->setMappingInformation(calcifiedRep->getParent()->getMappingInformation());
            getDataContainer().addData("image.tc", id);
        }
        else {
            LERROR("Could not create fused TC image.");
        }

        getDataContainer().removeData("image.calcified");
        getDataContainer().removeData("image.fibrotic" );
        getDataContainer().removeData("image.lipidic"  );
        getDataContainer().removeData("image.necrotic" );
    }

    void IvusTcDemo::readImage(const std::string& baseDir, const std::string& id) {
        _imageReader.p_inputDirectory.setValue(baseDir);
        _imageReader.p_outputImage.setValue(id);
        _imageReader.process(getDataContainer());
    }

192
193

}