Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

campcommhdreceiver.cpp 6.8 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
27
28
29
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

30
31
#define CAMPCOM_FAST_SERIALIZATION

32
33
34
35
#include "campcommhdreceiver.h"

#include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
36
#include "core/tools/stringutils.h"
37
38
39
40
41
42
43
44
45
46
47
48
49

namespace campvis {
    const std::string CampcomMhdReceiver::loggerCat_ = "CAMPVis.modules.io.CampcomMhdReceiver";

    CampcomMhdReceiver::CampcomMhdReceiver() 
        : AbstractProcessor()
        , p_address("ServerAddress", "Server Address", "127.0.0.1")
        , p_connect("Connect", "Connect to Server", AbstractProcessor::VALID)
        , p_targetImageID("targetImageName", "Target Image ID", "CampcomMhdReceiver.output", DataNameProperty::WRITE)
        , p_imageOffset("ImageOffset", "Image Offset in mm", tgt::vec3(0.f), tgt::vec3(-10000.f), tgt::vec3(10000.f), tgt::vec3(0.1f))
        , p_voxelSize("VoxelSize", "Voxel Size in mm", tgt::vec3(1.f), tgt::vec3(-100.f), tgt::vec3(100.f), tgt::vec3(0.1f))
        , _ccclient(0)
    {
50
51
        _incomingMhd = 0;

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
        addProperty(&p_address);
        addProperty(&p_targetImageID);
        addProperty(&p_connect);
        addProperty(&p_imageOffset);
        addProperty(&p_voxelSize);

    }

    CampcomMhdReceiver::~CampcomMhdReceiver() {

    }

    void CampcomMhdReceiver::init() {
        p_connect.s_clicked.connect(this, &CampcomMhdReceiver::onBtnConnectClicked);
    }

    void CampcomMhdReceiver::deinit() {
        p_connect.s_clicked.disconnect(this);
70
71
72
73
        if (_ccclient) {
            _ccclient->disconnect();
            delete _ccclient;
        }
74
75
76
77
        _ccclient = 0;
    }

    void CampcomMhdReceiver::process(DataContainer& data) {
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
        validate(INVALID_RESULT);

        campcom::MHDImageData* mid = _incomingMhd.fetch_and_store(0);
        if (mid == 0)
            return;

        int numChannels = 1;
        size_t dimensionality = mid->NDims;
        tgt::svec3 size(1);
        for (int i = 0; i < mid->DimSize.size(); ++i)
            size.elem[i] = mid->DimSize[i];

        WeaklyTypedPointer wtp;
        wtp._pointer = &(mid->imageData.front().front());
        wtp._numChannels = numChannels;

        std::string et = StringUtils::uppercase(mid->elementType);
        if (et == "MET_UCHAR")
            wtp._baseType = WeaklyTypedPointer::UINT8;
        else if (et == "MET_CHAR")
            wtp._baseType = WeaklyTypedPointer::INT8;
        else if (et == "MET_USHORT")
            wtp._baseType = WeaklyTypedPointer::UINT16;
        else if (et == "MET_SHORT")
            wtp._baseType = WeaklyTypedPointer::INT16;
        else if (et == "MET_UINT")
            wtp._baseType = WeaklyTypedPointer::UINT32;
        else if (et == "MET_INT")
            wtp._baseType = WeaklyTypedPointer::INT32;
        else if (et == "MET_FLOAT")
            wtp._baseType = WeaklyTypedPointer::FLOAT;
        else {
            LERROR("Error while parsing MHD header: Unsupported element type: " << et);
            return;
        }

        tgt::vec3 imageOffset(0.f);
        tgt::vec3 voxelSize(1.f);

117
        // all parsing done - lets create the image:
118
119
120
121
        ImageData* image = new ImageData(dimensionality, size, numChannels);
        ImageRepresentationLocal::create(image, wtp);
        image->setMappingInformation(ImageMappingInformation(size, imageOffset + p_imageOffset.getValue(), voxelSize * p_voxelSize.getValue()));
        data.addData(p_targetImageID.getValue(), image);
122
123
124
125
126
127
128
129
130
131
132

        validate(INVALID_RESULT);
    }

    void CampcomMhdReceiver::onBtnConnectClicked() {
        if (_ccclient) {
            _ccclient->disconnect();
            delete _ccclient;
            _ccclient = 0;
        }

133
        _ccclient = new campcom::CAMPComClient("Campvis", campcom::Device_TestDevice, p_address.getValue());
134
135
136
137
138
139
140
141
142
        _ccclient->connect();
        if (_ccclient->isConnected()) {
            campcom::DataCallback dc;
            dc = boost::bind(&CampcomMhdReceiver::ccReceiveImage, this, _1);
            campcom::SuccessCallback sc = std::bind1st(std::mem_fun(&CampcomMhdReceiver::ccSuccessCalback), this);
            _ccclient->subscribe(campcom::Type_Image, dc, sc);
        }
        else {
            LWARNING("Could not connect to CAMPCom server.");
143
//            delete _ccclient;
144
145
146
147
148
            _ccclient = 0;
        }
    }

    void CampcomMhdReceiver::ccReceiveImage(std::vector<campcom::Byte>& msg) {
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
        campcom::MHDImageData return_payload;
        campcom::Header header;

        campcom::TypeHandler<campcom::MHDImageData>::deserializePayload(&msg[0], msg.size(), return_payload);
        if (campcom::MHDImageData::isValid(return_payload)) {
            LINFO("New valid MHDImageData received! Pushing it to the DataContainer...");
            campcom::MHDImageData* copy = new campcom::MHDImageData(return_payload);
            campcom::MHDImageData* toDelete = _incomingMhd.fetch_and_store(copy);
            delete toDelete;

            invalidate(INVALID_RESULT);
        }
        else {
            LWARNING("New MHDImageData received but it isn't valid!");
        }
164
165
166
167
168
169
170
171

    }

    void CampcomMhdReceiver::ccSuccessCalback(bool b) {
        LINFO("CAMPCom subscribe callback: " << b);
    }

}