| 1 |
///////////////////////////////////////////////////////////// |
| 2 |
// // |
| 3 |
// Copyright (c) 2007-2017 by The University of Queensland // |
| 4 |
// Centre for Geoscience Computing // |
| 5 |
// http://earth.uq.edu.au/centre-geoscience-computing // |
| 6 |
// // |
| 7 |
// Primary Business: Brisbane, Queensland, Australia // |
| 8 |
// Licensed under the Open Software License version 3.0 // |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 // |
| 10 |
// // |
| 11 |
///////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
#include "TriPatchSet.h" |
| 14 |
|
| 15 |
TriPatchSet::TriPatchSet() |
| 16 |
{ |
| 17 |
m_bbx_set=false; |
| 18 |
} |
| 19 |
|
| 20 |
/*! |
| 21 |
check if a line between the given points crosses the triangle |
| 22 |
and return the triangle tag, -1 otherwise |
| 23 |
|
| 24 |
\param p1 |
| 25 |
\param p2 |
| 26 |
*/ |
| 27 |
int TriPatchSet::isCrossing(const Vector3& p1, const Vector3& p2) const |
| 28 |
{ |
| 29 |
int res=-1; |
| 30 |
|
| 31 |
vector<Triangle3D>::const_iterator iter=m_triangles.begin(); |
| 32 |
while((iter!=m_triangles.end()) && (res==-1)){ |
| 33 |
if(iter->crosses(p1,p2)) res=iter->getTag(); |
| 34 |
iter++; |
| 35 |
} |
| 36 |
|
| 37 |
return res; |
| 38 |
} |
| 39 |
|
| 40 |
void TriPatchSet::addTriangle(const Vector3& p1, const Vector3& p2, const Vector3& p3,int tag) |
| 41 |
{ |
| 42 |
Triangle3D T=Triangle3D(p1,p2,p3,tag); |
| 43 |
Vector3 tmin=T.getMinPoint(); |
| 44 |
Vector3 tmax=T.getMaxPoint(); |
| 45 |
m_triangles.push_back(Triangle3D(p1,p2,p3,tag)); |
| 46 |
// update bounding box |
| 47 |
if(m_bbx_set){ // already have bbx -> update |
| 48 |
m_pmin.X()=(m_pmin.X() < tmin.X()) ? m_pmin.X() : tmin.X(); |
| 49 |
m_pmin.Y()=(m_pmin.Y() < tmin.Y()) ? m_pmin.Y() : tmin.Y(); |
| 50 |
m_pmin.Z()=(m_pmin.Z() < tmin.Z()) ? m_pmin.Z() : tmin.Z(); |
| 51 |
m_pmax.X()=(m_pmax.X() > tmax.X()) ? m_pmax.X() : tmax.X(); |
| 52 |
m_pmax.Y()=(m_pmax.Y() > tmax.Y()) ? m_pmax.Y() : tmax.Y(); |
| 53 |
m_pmax.Z()=(m_pmax.Z() > tmax.Z()) ? m_pmax.Z() : tmax.Z(); |
| 54 |
} else { // no bbx yet -> initialize |
| 55 |
m_pmin=tmin; |
| 56 |
m_pmax=tmax; |
| 57 |
m_bbx_set=true; |
| 58 |
} |
| 59 |
//std::cout << "patch set size: " << m_triangles.size() |
| 60 |
//<< " bbx: " << m_pmin << " - " << m_pmax << std::endl; |
| 61 |
} |