1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : VISU_PrsObject_i.cxx
24 // Author : Alexey PETROV
27 #include "VISU_CutLinesPL.hxx"
28 #include "VISU_Result_i.hh"
29 #include "VISU_CutLines_i.hh"
30 #include "VISU_Actor.h"
32 #include "VISU_PipeLineUtils.hxx"
34 #include <vtkAppendPolyData.h>
40 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
45 int VISU::CutLines_i::IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,
46 const char* theFieldName, int theIteration, int isMemoryCheck)
48 return VISU::ScalarMap_i::IsPossible(theResult,theMeshName,theEntity,theFieldName,theIteration,isMemoryCheck);
51 int VISU::CutLines_i::myNbPresent = 0;
52 QString VISU::CutLines_i::GenerateName() { return VISU::GenerateName("CutLines",myNbPresent++);}
54 const string VISU::CutLines_i::myComment = "CUTLINES";
55 const char* VISU::CutLines_i::GetComment() const { return myComment.c_str();}
59 CutLines_i(Result_i* theResult,
61 PrsObject_i(theResult->GetStudyDocument()),
62 Prs3d_i(theResult,theAddToStudy),
63 ScalarMap_i(theResult,theAddToStudy),
70 CutLines_i(Result_i* theResult,
71 SALOMEDS::SObject_ptr theSObject) :
72 PrsObject_i(theResult->GetStudyDocument()),
73 Prs3d_i(theResult,theSObject),
74 ScalarMap_i(theResult,theSObject),
80 void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin){
81 VISU::ScalarMap_i::SameAs(theOrigin);
85 VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity,
86 const char* theFieldName, int theIteration)
88 return ScalarMap_i::Create(theMeshName,theEntity,theFieldName,theIteration);
92 VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap)
95 SetNbLines(VISU::Storable::FindValue(theMap,"myNbLines").toInt());
96 SetDisplacement(VISU::Storable::FindValue(theMap,"myDisplacement[0]").toDouble());
97 SetDisplacement2(VISU::Storable::FindValue(theMap,"myDisplacement[1]").toDouble());
98 SetOrientation(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[0]").toInt()),
99 Storable::FindValue(theMap,"aRot[0][0]").toDouble(),
100 Storable::FindValue(theMap,"aRot[0][1]").toDouble());
101 SetOrientation2(CutPlanes::Orientation(VISU::Storable::FindValue(theMap,"myBasePlane[1]").toInt()),
102 Storable::FindValue(theMap,"aRot[1][0]").toDouble(),
103 Storable::FindValue(theMap,"aRot[1][1]").toDouble());
104 if (VISU::Storable::FindValue(theMap,"myBasePlaneCondition").toInt())
107 SetBasePlanePosition(VISU::Storable::FindValue(theMap,"myBasePlanePosition").toDouble());
109 QStringList aPosList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myLinePosition") );
110 QStringList aCondList = QStringList::split("|",VISU::Storable::FindValue(theMap,"myLineCondition") );
111 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++)
112 if(aCondList[i].toInt() == 0)
113 SetLinePosition(i,aPosList[i].toDouble());
115 return ScalarMap_i::Restore(theMap);
119 void VISU::CutLines_i::ToStream(std::ostringstream& theStr){
120 ScalarMap_i::ToStream(theStr);
122 int aNbLines = GetNbLines();
124 Storable::DataToStream( theStr, "myNbLines", aNbLines );
125 Storable::DataToStream( theStr, "myDisplacement[0]", GetDisplacement() );
126 Storable::DataToStream( theStr, "myDisplacement[1]", GetDisplacement2() );
127 Storable::DataToStream( theStr, "myBasePlane[0]", int(GetOrientationType()) );
128 Storable::DataToStream( theStr, "myBasePlane[1]", int(GetOrientationType2()) );
129 Storable::DataToStream( theStr, "aRot[0][0]", GetRotateX() );
130 Storable::DataToStream( theStr, "aRot[0][1]", GetRotateY() );
131 Storable::DataToStream( theStr, "aRot[1][0]", GetRotateX2() );
132 Storable::DataToStream( theStr, "aRot[1][1]", GetRotateY2() );
133 Storable::DataToStream( theStr, "myBasePlanePosition", GetBasePlanePosition() );
134 Storable::DataToStream( theStr, "myBasePlaneCondition", IsDefault() );
136 QString aStrPos, aStrCon;
137 for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++){
138 aStrPos.append(QString::number(GetLinePosition(i)) + "|");
139 aStrCon.append(QString::number(IsDefaultPosition(i)) + "|");
141 Storable::DataToStream( theStr, "myLinePosition", aStrPos.latin1());
142 Storable::DataToStream( theStr, "myLineCondition", aStrCon.latin1());
145 VISU::CutLines_i::~CutLines_i(){
146 if(MYDEBUG) MESSAGE("CutLines_i::~CutLines_i()");
150 void VISU::CutLines_i::SetOrientation(VISU::CutPlanes::Orientation theOrient,
151 CORBA::Double theXAngle, CORBA::Double theYAngle)
153 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),
154 theXAngle,theYAngle);
156 void VISU::CutLines_i::SetOrientation2(VISU::CutPlanes::Orientation theOrient,
157 CORBA::Double theXAngle, CORBA::Double theYAngle)
159 myCutLinesPL->SetOrientation(VISU_CutPlanesPL::PlaneOrientation(theOrient),
160 theXAngle,theYAngle,1);
163 VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType() {
164 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation());
166 VISU::CutPlanes::Orientation VISU::CutLines_i::GetOrientationType2() {
167 return VISU::CutPlanes::Orientation(myCutLinesPL->GetPlaneOrientation(1));
170 CORBA::Double VISU::CutLines_i::GetRotateX(){
171 return myCutLinesPL->GetRotateX();
173 CORBA::Double VISU::CutLines_i::GetRotateY(){
174 return myCutLinesPL->GetRotateY();
177 CORBA::Double VISU::CutLines_i::GetRotateX2(){
178 return myCutLinesPL->GetRotateX(1);
180 CORBA::Double VISU::CutLines_i::GetRotateY2(){
181 return myCutLinesPL->GetRotateY(1);
185 void VISU::CutLines_i::SetDisplacement(CORBA::Double theDisp) {
186 myCutLinesPL->SetDisplacement(theDisp);
188 void VISU::CutLines_i::SetDisplacement2(CORBA::Double theDisp) {
189 myCutLinesPL->SetDisplacement(theDisp,1);
192 CORBA::Double VISU::CutLines_i::GetDisplacement() {
193 return myCutLinesPL->GetDisplacement();
195 CORBA::Double VISU::CutLines_i::GetDisplacement2() {
196 return myCutLinesPL->GetDisplacement(1);
200 void VISU::CutLines_i::SetBasePlanePosition(CORBA::Double thePlanePosition){
201 myCutLinesPL->SetPosition(thePlanePosition);
204 CORBA::Double VISU::CutLines_i::GetBasePlanePosition(){
205 return myCutLinesPL->GetPosition();
208 void VISU::CutLines_i::SetLinePosition(CORBA::Long thePlaneNumber, CORBA::Double thePlanePosition){
209 myCutLinesPL->SetPartPosition(thePlaneNumber,thePlanePosition);
212 CORBA::Double VISU::CutLines_i::GetLinePosition(CORBA::Long thePlaneNumber){
213 return myCutLinesPL->GetPartPosition(thePlaneNumber,1);
217 void VISU::CutLines_i::SetDefault(){
218 myCutLinesPL->SetDefault();
221 CORBA::Boolean VISU::CutLines_i::IsDefault(){
222 return myCutLinesPL->IsDefault();
225 void VISU::CutLines_i::SetDefaultPosition(CORBA::Long thePlaneNumber){
226 myCutLinesPL->SetPartDefault(thePlaneNumber);
229 CORBA::Boolean VISU::CutLines_i::IsDefaultPosition(CORBA::Long thePlaneNumber){
230 return myCutLinesPL->IsPartDefault(thePlaneNumber);
234 void VISU::CutLines_i::SetNbLines(CORBA::Long theNb) {
235 myCutLinesPL->SetNbParts(theNb);
237 CORBA::Long VISU::CutLines_i::GetNbLines() {
238 return myCutLinesPL->GetNbParts();
242 void VISU::CutLines_i::DoHook(){
243 if(!myPipeLine) myPipeLine = VISU_CutLinesPL::New();
244 myCutLinesPL = dynamic_cast<VISU_CutLinesPL*>(myPipeLine);
246 ScalarMap_i::DoHook();
249 void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){
251 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal");
253 SALOMEDS::GenericAttribute_var anAttr;
254 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
255 anAttr = aStudyBuilder->FindOrCreateAttribute(theSObject, "AttributeTableOfReal");
256 SALOMEDS::AttributeTableOfReal_var aTableOfReal = SALOMEDS::AttributeTableOfReal::_narrow(anAttr);
258 typedef set<float> TXCont;
259 typedef map<float,float> TXYMap;
260 typedef map<int,TXYMap> TXYMapCont;
261 typedef map<long,long> TLineIdCont;
264 aTitle.sprintf("%s",myTitle.c_str());
265 aTitle = aTitle.simplifyWhiteSpace();
266 aTableOfReal->SetTitle(aTitle.latin1());
268 int iLineEnd = myCutLinesPL->GetAppendPolyData()->GetNumberOfInputs();
269 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLineEnd = "<<iLineEnd);
271 TXYMapCont aXYMapCont;
272 TLineIdCont aLineIdCont; // Define internal numeration of lines
273 const float *aDirLn = myCutLinesPL->GetDirLn();
274 const float *aBasePnt = myCutLinesPL->GetBasePnt();
275 const float *aBoundPrjLn = myCutLinesPL->GetBoundPrjLn();
276 for(int iLine = 0, jLine = 0; iLine < iLineEnd; iLine++){
277 vtkDataSet *aDataSet = myCutLinesPL->GetAppendPolyData()->GetInput(iLine);
279 int aNbPoints = aDataSet->GetNumberOfPoints();
280 if(!aNbPoints) continue;
281 vtkPointData *aPointData = aDataSet->GetPointData();
282 vtkDataArray *aScalars = aPointData->GetScalars();
283 vtkCellDataToPointData *aFilter = NULL;
285 aFilter = vtkCellDataToPointData::New();
286 aFilter->SetInput(aDataSet);
287 aFilter->PassCellDataOn();
288 aDataSet = aFilter->GetOutput();
291 aPointData = aDataSet->GetPointData();
292 aScalars = aPointData->GetScalars();
293 if(!aScalars) continue;
294 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal iLine = "<<iLine<<"; aNbPoints = "<<aNbPoints);
295 aLineIdCont[iLine] = jLine++;
296 TXYMap& aXYMap = aXYMapCont[iLine];
297 float aPnt[3], aVect[3], aDist;
298 for(int i = 0; i < aNbPoints; i++){
299 aDataSet->GetPoint(i,aPnt);
300 Sub(aPnt,aBasePnt,aVect);
301 aDist = vtkMath::Dot(aVect,aDirLn) / aBoundPrjLn[2];
303 if(aDist < 0.0) aDist = 0.0;
304 if(aDist > 1.0) aDist = 1.0;
305 aXYMap[aDist] = aScalars->GetTuple1(i);
308 aFilter->UnRegisterAllOutputs();
312 if(aXYMapCont.size() == 0)
313 throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXYMapCont.size() == 0 !!!");
314 //Resorting of theXYMap
315 TXYMapCont::iterator aXYMapContIter = aXYMapCont.begin();
316 for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
317 TXYMap& aXYMap = aXYMapContIter->second, aNewXYMap;
318 if(aXYMap.size() > 2){
319 // Try to smooth the values of the line by applying linear approximation
320 TXYMap::const_iterator aXYMapIter[2] = {aXYMap.begin(), ++aXYMap.begin()};
321 aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
322 aXCont.insert(aXYMapIter[0]->first);
323 for(; aXYMapIter[1] != aXYMap.end(); aXYMapIter[0]++, aXYMapIter[1]++){
324 float aY[3] = {aXYMapIter[0]->second, aXYMapIter[1]->second, 0.0};
325 aY[2] = (aY[0] + aY[1])/2.0;
326 float aX[3] = {aXYMapIter[0]->first, aXYMapIter[1]->first, 0.0};
327 aX[2] = (aX[0] + aX[1])/2.0;
328 aNewXYMap[aX[2]] = aY[2];
329 aXCont.insert(aX[2]);
331 aNewXYMap[aXYMapIter[0]->first] = aXYMapIter[0]->second;
332 aXCont.insert(aXYMapIter[0]->first);
335 TXYMap::const_iterator aXYMapIter = aXYMap.begin();
336 for(; aXYMapIter != aXYMap.end(); aXYMapIter++)
337 aXCont.insert(aXYMapIter->first);
340 if(aXCont.size() == 0)
341 throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXCont.size() == 0 !!!");
343 int iEnd = aXCont.size();
344 aTableOfReal->SetNbColumns(iEnd);
345 TXCont::const_iterator aXContIter = aXCont.begin();
346 for(long i = 0; aXContIter != aXCont.end(); aXContIter++, i++){
347 float aDist = *aXContIter;
348 aTableOfReal->PutValue(aDist,1,i+1);
349 aString.sprintf("%d",i);
350 aTableOfReal->SetColumnTitle(i+1,aString.latin1());
351 if(MYDEBUG) MESSAGE("CutPlanes_i::BuildTableOfReal aDist = "<<aDist);
352 TXYMapCont::const_iterator aXYMapContIter = aXYMapCont.begin();
353 for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
354 long iLine = aXYMapContIter->first;
355 long iLineId = aLineIdCont[iLine];
356 const TXYMap& aXYMap = aXYMapCont[iLine];
357 TXYMap::const_iterator aXYMapIter = aXYMap.find(aDist);
358 // Can we find some value that belong to the line and have the same X coordinate?
359 if(aXYMapIter == aXYMap.end()) continue;
360 float aVal = aXYMapIter->second;
361 aTableOfReal->PutValue(aVal,iLineId+2,i+1);
365 aTableOfReal->SetRowTitle(1,"X");
366 aTableOfReal->SetRowUnit(1,"-");
367 QString aUnitName = myField->myUnitNames[0].c_str();
368 int aScalarMode = myCutLinesPL->GetScalarMode();
370 aUnitName = myField->myUnitNames[aScalarMode-1].c_str();
371 aUnitName = aUnitName.simplifyWhiteSpace();
372 if(aUnitName.isEmpty()) aUnitName = "-";
373 TXYMapCont::const_iterator aXYMapContIter = aXYMapCont.begin();
374 for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){
375 long iLine = aXYMapContIter->first;
376 long iLineId = aLineIdCont[iLine];
377 aString.sprintf("Y%d",iLine);
379 MESSAGE("CutPlanes_i::BuildTableOfReal - SetRowTitle("<<iLineId+2<<",'"<<aString<<"')");
380 aTableOfReal->SetRowTitle(iLineId+2,aString.latin1());
381 aTableOfReal->SetRowUnit(iLineId+2,aUnitName.latin1());
384 }catch(std::exception& exc){
385 INFOS("Follow exception was occured :\n"<<exc.what());
387 INFOS("Unknown exception was occured !!!");