2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------
26 /*=========================================================================
32 =========================================================================*/
34 /* ---------------------------------------------------------------------
36 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
37 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
39 * This software is governed by the CeCILL-B license under French law and
40 * abiding by the rules of distribution of free software. You can use,
41 * modify and/ or redistribute the software under the terms of the CeCILL-B
42 * license as circulated by CEA, CNRS and INRIA at the following URL
43 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
44 * or in the file LICENSE.txt.
46 * As a counterpart to the access to the source code and rights to copy,
47 * modify and redistribute granted by the license, users are provided only
48 * with a limited warranty and the software's author, the holder of the
49 * economic rights, and the successive licensors have only limited
52 * The fact that you are presently reading this means that you have had
53 * knowledge of the CeCILL-B license and that you accept its terms.
54 * ------------------------------------------------------------------------ */
58 * \brief Class bbtk::GConnectorModel
62 #include "GConnectorModel.h"
67 //=========================================================================
69 GConnectorModel::GConnectorModel()
75 //=========================================================================
77 GConnectorModel::~GConnectorModel()
81 //=========================================================================
83 void GConnectorModel::setStartPort(GPortModel* startPort)
85 _startPort = startPort;
86 startPort->setConnected(true);
88 double xCenter,yCenter,zCenter;
89 startPort->getCenter(xCenter,yCenter,zCenter);
90 double xFport,yFport,zFport;
91 startPort->getFinalPoint(xFport,yFport,zFport);
93 setInicPoint(xCenter,yFport,zCenter);
96 //=========================================================================
98 void GConnectorModel::setEndPort(GPortModel* endPort)
101 endPort->setConnected(true);
103 double xCenter,yCenter,zCenter;
104 endPort->getCenter(xCenter,yCenter,zCenter);
105 double xIport,yIport,zIport;
106 endPort->getInicPoint(xIport,yIport,zIport);
108 setFinalPoint(xCenter,yIport,zCenter);
110 // Sets the last point of the contour model in the position of the end input port
111 manualPoint* point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
112 point->SetPoint(xCenter,yIport,zCenter);
115 //=========================================================================
117 GPortModel* GConnectorModel::getStartPort()
122 //=========================================================================
124 GPortModel* GConnectorModel::getEndPort()
129 //=========================================================================
131 manualContourModel* GConnectorModel::getManualContourModel()
136 //=========================================================================
138 void GConnectorModel::setManualContourModel(manualContourModel* model)
143 //=========================================================================
145 void GConnectorModel::updateStartEndPoints()
149 double bsx,bsy; // back start for x and y
151 double bex,bey; // new start for x and y
155 double xCenter,yCenter,zCenter;
156 _startPort->getCenter(xCenter,yCenter,zCenter);
157 double xport,yport,zport;
158 _startPort->getFinalPoint(xport,yport,zport);
160 // Refresh the position of the contourModel first point with the data of the connector model
161 manualPoint* point = _model->GetManualPoint(0);
164 point->SetPoint(xCenter,yport,zCenter);
169 _endPort->getCenter(xCenter,yCenter,zCenter);
170 _endPort->getInicPoint(xport,yport,zport);
172 // Refresh the position of the contourModel last point with the data of the connector model
173 point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
176 point->SetPoint(xCenter,yport,zCenter);
181 // moving point of the spline connection
182 if ( ((bsx!=nsx)&&(bex!=nex)) || ((bsy!=nsy)&&(bey!=ney)) )
184 double difx = bsx-nsx;
185 double dify = bey-ney;
186 double tmpX, tmpY, tmpZ;
187 int i,size=_model->GetSizeLstPoints();
190 for (i=1;i<size-1;i++)
192 point = _model->GetManualPoint(i);
193 tmpX = point->GetX();
194 tmpY = point->GetY();
195 tmpZ = point->GetZ();
196 point->SetPoint(tmpX-difx,tmpY-dify,tmpZ);
199 } // if bsx nsx bex nex bsy nsy bey ney
202 //=========================================================================
204 void GConnectorModel::disconnectConnection()
208 _startPort->setConnected(false);
213 _endPort->setConnected(false);
217 //=========================================================================
219 void GConnectorModel::save(std::string &content)
223 content+="CONNECTION\n";
226 content+=_startPort->getParentBox()->getBBTKName();
228 content+=_startPort->getBBTKName();
230 content+=_endPort->getParentBox()->getBBTKName();
232 content+=_endPort->getBBTKName();
235 int i,sizeLstPoints = _model->GetSizeLstPoints()-2;
236 content+="NumberOfControlPoints:";
237 sprintf (buffer, "%d", sizeLstPoints );
241 for (i=0;i<sizeLstPoints;i++)
243 manualPoint *mp = _model->GetManualPoint(i+1);
244 sprintf (buffer, "%f:%f:%f\n", (float)mp->GetX(),(float)mp->GetY(),(float)mp->GetZ() );
249 //=========================================================================
251 } // EO namespace bbtk