1 /*=========================================================================
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Class bbtk::GConnectorModel
37 #include "GConnectorModel.h"
42 //=========================================================================
44 GConnectorModel::GConnectorModel()
50 //=========================================================================
52 GConnectorModel::~GConnectorModel()
56 //=========================================================================
58 void GConnectorModel::setStartPort(GPortModel* startPort)
60 _startPort = startPort;
61 startPort->setConnected(true);
63 double xCenter,yCenter,zCenter;
64 startPort->getCenter(xCenter,yCenter,zCenter);
65 double xFport,yFport,zFport;
66 startPort->getFinalPoint(xFport,yFport,zFport);
68 setInicPoint(xCenter,yFport,zCenter);
71 //=========================================================================
73 void GConnectorModel::setEndPort(GPortModel* endPort)
76 endPort->setConnected(true);
78 double xCenter,yCenter,zCenter;
79 endPort->getCenter(xCenter,yCenter,zCenter);
80 double xIport,yIport,zIport;
81 endPort->getInicPoint(xIport,yIport,zIport);
83 setFinalPoint(xCenter,yIport,zCenter);
85 // Sets the last point of the contour model in the position of the end input port
86 manualPoint* point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
87 point->SetPoint(xCenter,yIport,zCenter);
90 //=========================================================================
92 GPortModel* GConnectorModel::getStartPort()
97 //=========================================================================
99 GPortModel* GConnectorModel::getEndPort()
104 //=========================================================================
106 manualContourModel* GConnectorModel::getManualContourModel()
111 //=========================================================================
113 void GConnectorModel::setManualContourModel(manualContourModel* model)
118 //=========================================================================
120 void GConnectorModel::updateStartEndPoints()
123 double xCenter,yCenter,zCenter;
124 _startPort->getCenter(xCenter,yCenter,zCenter);
125 double xport,yport,zport;
126 _startPort->getFinalPoint(xport,yport,zport);
128 // Refresh the position of the contourModel first point with the data of the connector model
129 manualPoint* point = _model->GetManualPoint(0);
130 point->SetPoint(xCenter,yport,zCenter);
133 _endPort->getCenter(xCenter,yCenter,zCenter);
134 _endPort->getInicPoint(xport,yport,zport);
136 // Refresh the position of the contourModel last point with the data of the connector model
137 point = _model->GetManualPoint(_model->GetSizeLstPoints()-1);
138 point->SetPoint(xCenter,yport,zCenter);
141 //=========================================================================
143 void GConnectorModel::disconnectConnection()
147 _startPort->setConnected(false);
152 _endPort->setConnected(false);
156 //=========================================================================
158 void GConnectorModel::save(std::string &content)
162 content+="CONNECTION\n";
165 content+=_startPort->getParentBox()->getBBTKName();
167 content+=_startPort->getBBTKName();
169 content+=_endPort->getParentBox()->getBBTKName();
171 content+=_endPort->getBBTKName();
174 int i,sizeLstPoints = _model->GetSizeLstPoints()-2;
175 content+="NumberOfControlPoints:";
176 sprintf (buffer, "%d", sizeLstPoints );
180 for (i=0;i<sizeLstPoints;i++)
182 manualPoint *mp = _model->GetManualPoint(i+1);
183 sprintf (buffer, "%f:%f:%f\n", (float)mp->GetX(),(float)mp->GetY(),(float)mp->GetZ() );
188 //=========================================================================
190 } // EO namespace bbtk