/* * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #include #include #include #include "tinyxml.h" #include "stdint.h" #include "CSPrimMultiBox.h" #include "CSProperties.h" #include "CSUseful.h" CSPrimMultiBox::CSPrimMultiBox(unsigned int ID, ParameterSet* paraSet, CSProperties* prop) : CSPrimitives(ID,paraSet,prop) { Type=MULTIBOX; PrimTypeName = std::string("Multi Box"); } CSPrimMultiBox::CSPrimMultiBox(CSPrimMultiBox* multiBox, CSProperties *prop) : CSPrimitives(multiBox, prop) { Type=MULTIBOX; for (size_t i=0;ivCoords.size();++i) vCoords.push_back(new ParameterScalar(multiBox->vCoords.at(i))); PrimTypeName = std::string("Multi Box"); } CSPrimMultiBox::CSPrimMultiBox(ParameterSet* paraSet, CSProperties* prop) : CSPrimitives(paraSet,prop) { Type=MULTIBOX; PrimTypeName = std::string("Multi Box"); } CSPrimMultiBox::~CSPrimMultiBox() { } void CSPrimMultiBox::SetCoord(int index, double val) { if ((index>=0) && (index<(int)vCoords.size())) vCoords.at(index)->SetValue(val); } void CSPrimMultiBox::SetCoord(int index, const char* val) { if ((index>=0) && (index<(int)vCoords.size())) vCoords.at(index)->SetValue(val); } void CSPrimMultiBox::AddCoord(double val) { vCoords.push_back(new ParameterScalar(clParaSet,val)); } void CSPrimMultiBox::AddCoord(const char* val) { vCoords.push_back(new ParameterScalar(clParaSet,val)); } void CSPrimMultiBox::AddBox(int initBox) { ClearOverlap(); if ((initBox<0) || (((initBox+1)*6)>(int)vCoords.size())) { for (unsigned int i=0;i<6;++i) AddCoord(0.0); } else for (unsigned int i=0;i<6;++i) vCoords.push_back(new ParameterScalar(vCoords.at(6*initBox+i))); } void CSPrimMultiBox::DeleteBox(size_t box) { if ((box+1)*6>vCoords.size()) return; std::vector::iterator start=vCoords.begin()+(box*6); std::vector::iterator end=vCoords.begin()+(box*6+6); vCoords.erase(start,end); } double CSPrimMultiBox::GetCoord(int index) { if ((index>=0) && (index<(int)vCoords.size())) return vCoords.at(index)->GetValue(); return 0; } ParameterScalar* CSPrimMultiBox::GetCoordPS(int index) { if ((index>=0) && (index<(int)vCoords.size())) return vCoords.at(index); return NULL; } double* CSPrimMultiBox::GetAllCoords(size_t &Qty, double* array) { Qty=vCoords.size(); delete[] array; array = new double[Qty]; for (size_t i=0;iGetValue(); return array; } void CSPrimMultiBox::ClearOverlap() { if (vCoords.size()%6==0) return; //no work to be done vCoords.resize(vCoords.size()-vCoords.size()%6); } bool CSPrimMultiBox::GetBoundBox(double dBoundBox[6], bool PreserveOrientation) { UNUSED(PreserveOrientation); //has no orientation or preserved anyways for (int n=0;n<6;++n) dBoundBox[n] = 0; //Update(); for (unsigned int i=0;iGetValue()<=vCoords.at(6*i+2*n+1)->GetValue()) { if (i==0) { dBoundBox[2*n]=vCoords.at(6*i+2*n)->GetValue(); dBoundBox[2*n+1]=vCoords.at(6*i+2*n+1)->GetValue(); } else { if (vCoords.at(6*i+2*n)->GetValue()GetValue(); if (vCoords.at(6*i+2*n+1)->GetValue()>dBoundBox[2*n+1]) dBoundBox[2*n+1]=vCoords.at(6*i+2*n+1)->GetValue(); } } else { if (i==0) { dBoundBox[2*n]=vCoords.at(6*i+2*n+1)->GetValue(); dBoundBox[2*n+1]=vCoords.at(6*i+2*n)->GetValue(); } else { if (vCoords.at(6*i+2*n+1)->GetValue()GetValue(); if (vCoords.at(6*i+2*n)->GetValue()>dBoundBox[2*n+1]) dBoundBox[2*n+1]=vCoords.at(6*i+2*n)->GetValue(); } } } } m_Dimension=0; m_BoundBox_CoordSys = m_MeshType; for (int n=0;n<3;++n) { if (dBoundBox[2*n]!=dBoundBox[2*n+1]) ++m_Dimension; } return false; } bool CSPrimMultiBox::IsInside(const double* Coord, double /*tol*/) { if (Coord==NULL) return false; bool in=false; double UpVal,DownVal; double coords[3]={Coord[0],Coord[1],Coord[2]}; TransformCoords(coords, true, m_MeshType); //fprintf(stderr,"here\n"); for (unsigned int i=0;iGetValue(),vCoords.at(6*i+2*n+1)->GetValue()); UpVal=vCoords.at(6*i+2*n+1)->GetValue(); DownVal=vCoords.at(6*i+2*n)->GetValue(); if (DownValcoords[n]) {in=false;break;} if (UpValcoords[n]) {in=false;break;} } } if (in==true) { return true;} } return false; } bool CSPrimMultiBox::Update(std::string *ErrStr) { int EC=0; bool bOK=true; for (size_t i=0;iEvaluate(); if (EC!=ParameterScalar::NO_ERROR) bOK=false; if ((EC!=0) && (ErrStr!=NULL)) { bOK=false; std::stringstream stream; stream << std::endl << "Error in MultiBox (ID: " << uiID << "): "; ErrStr->append(stream.str()); PSErrorCode2Msg(EC,ErrStr); } } //update local bounding box m_BoundBoxValid = GetBoundBox(m_BoundBox); return bOK; } bool CSPrimMultiBox::Write2XML(TiXmlElement &elem, bool parameterised) { CSPrimitives::Write2XML(elem,parameterised); elem.SetAttribute("QtyBox",(int)vCoords.size()/6); for (size_t i=0;iAddCoord(0.0); if (ReadTerm(*vCoords.at(i*6),*SP,"X")==false) return false; if (ReadTerm(*vCoords.at(i*6+2),*SP,"Y")==false) return false; if (ReadTerm(*vCoords.at(i*6+4),*SP,"Z")==false) return false; if (ReadTerm(*vCoords.at(i*6+1),*EP,"X")==false) return false; if (ReadTerm(*vCoords.at(i*6+3),*EP,"Y")==false) return false; if (ReadTerm(*vCoords.at(i*6+5),*EP,"Z")==false) return false; // for (int n=0;n<6;++n) fprintf(stderr,"%e ",vCoords.at(i*6+n)->GetValue()); // fprintf(stderr,"\n"); SP=SP->NextSiblingElement("StartP"); EP=EP->NextSiblingElement("EndP"); ++i; }; return true; }