本文整理汇总了C++中CCVector3::norm2方法的典型用法代码示例。如果您正苦于以下问题:C++ CCVector3::norm2方法的具体用法?C++ CCVector3::norm2怎么用?C++ CCVector3::norm2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCVector3
的用法示例。
在下文中一共展示了CCVector3::norm2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportFacets
//.........这里部分代码省略.........
CCVector3 X(1,0,0), Y(0,1,0), Z(0,0,1);
//'vertical' orientation (potentially specified by the user)
if (!useNativeOrientation)
{
if (useCustomOrientation)
{
Z = CCVector3( static_cast<PointCoordinateType>(fDlg.nXLineEdit->text().toDouble()),
static_cast<PointCoordinateType>(fDlg.nYLineEdit->text().toDouble()),
static_cast<PointCoordinateType>(fDlg.nZLineEdit->text().toDouble()) );
Z.normalize();
}
else if (useGlobalOrientation)
{
//we compute the mean orientation (weighted by each facet's surface)
CCVector3d Nsum(0,0,0);
for (std::set<ccFacet*>::iterator it = facets.begin(); it != facets.end(); ++it)
{
double surf = (*it)->getSurface();
CCVector3 N = (*it)->getNormal();
Nsum.x += static_cast<double>(N.x) * surf;
Nsum.y += static_cast<double>(N.y) * surf;
Nsum.z += static_cast<double>(N.z) * surf;
}
Nsum.normalize();
Z = CCVector3( static_cast<PointCoordinateType>(Nsum.x),
static_cast<PointCoordinateType>(Nsum.y),
static_cast<PointCoordinateType>(Nsum.z) );
}
//update X & Y
CCVector3 D = Z.cross(CCVector3(0,0,1));
if (D.norm2() > ZERO_TOLERANCE) //otherwise the vertical dir hasn't changed!
{
X = -D;
X.normalize();
Y = Z.cross(X);
}
}
//we compute the mean center (weighted by each facet's surface)
CCVector3 C(0,0,0);
{
double weightSum = 0;
for (std::set<ccFacet*>::iterator it = facets.begin(); it != facets.end(); ++it)
{
double surf = (*it)->getSurface();
CCVector3 Ci = (*it)->getCenter();
C += Ci * static_cast<PointCoordinateType>(surf);
weightSum += surf;
}
if (weightSum)
C /= static_cast<PointCoordinateType>(weightSum);
}
//determine the 'global' orientation matrix
ccGLMatrix oriRotMat;
oriRotMat.toIdentity();
if (!useNativeOrientation)
{
oriRotMat.getColumn(0)[0] = static_cast<float>(X.x);
oriRotMat.getColumn(0)[1] = static_cast<float>(X.y);
oriRotMat.getColumn(0)[2] = static_cast<float>(X.z);
oriRotMat.getColumn(1)[0] = static_cast<float>(Y.x);
oriRotMat.getColumn(1)[1] = static_cast<float>(Y.y);
示例2: removeHiddenPoints
CCLib::ReferenceCloud* qHPR::removeHiddenPoints(CCLib::GenericIndexedCloudPersist* theCloud, const CCVector3& viewPoint, float fParam)
{
assert(theCloud);
unsigned nbPoints = theCloud->size();
if (nbPoints == 0)
return 0;
//less than 4 points? no need for calculation, we return the whole cloud
if (nbPoints < 4)
{
CCLib::ReferenceCloud* visiblePoints = new CCLib::ReferenceCloud(theCloud);
if (!visiblePoints->addPointIndex(0,nbPoints)) //well even for less than 4 points we never know ;)
{
//not enough memory!
delete visiblePoints;
visiblePoints = 0;
}
return visiblePoints;
}
PointCoordinateType maxRadius = 0;
//convert point cloud to an array of double triplets (for qHull)
coordT* pt_array = new coordT[(nbPoints+1)*3];
{
coordT* _pt_array = pt_array;
for (unsigned i=0; i<nbPoints; ++i)
{
CCVector3 P = *theCloud->getPoint(i) - viewPoint;
*_pt_array++ = (coordT)P.x;
*_pt_array++ = (coordT)P.y;
*_pt_array++ = (coordT)P.z;
//we keep track of the highest 'radius'
PointCoordinateType r2 = P.norm2();
if (maxRadius < r2)
maxRadius = r2;
}
//we add the view point (Cf. HPR)
*_pt_array++ = 0;
*_pt_array++ = 0;
*_pt_array++ = 0;
maxRadius = sqrt(maxRadius);
}
//apply spherical flipping
{
maxRadius *= 2.0f*pow(10.0f,fParam);
coordT* _pt_array = pt_array;
for (unsigned i=0; i<nbPoints; ++i)
{
CCVector3 P = *theCloud->getPoint(i) - viewPoint;
double r = (double)(maxRadius/P.norm()) - 1.0;
*_pt_array++ *= r;
*_pt_array++ *= r;
*_pt_array++ *= r;
}
}
//array to flag points on the convex hull
std::vector<bool> pointBelongsToCvxHull;
if (!qh_new_qhull(3,nbPoints+1,pt_array,False,(char*)"qhull QJ Qci",0,stderr))
{
try
{
pointBelongsToCvxHull.resize(nbPoints+1,false);
}
catch(std::bad_alloc)
{
//not enough memory!
delete[] pt_array;
return 0;
}
vertexT *vertex = 0,**vertexp = 0;
facetT *facet = 0;
FORALLfacets
{
//if (!facet->simplicial)
// error("convhulln: non-simplicial facet"); // should never happen with QJ
setT* vertices = qh_facet3vertex(facet);
FOREACHvertex_(vertices)
{
pointBelongsToCvxHull[qh_pointid(vertex->point)] = true;
}
qh_settempfree(&vertices);
}
}
delete[] pt_array;
pt_array=0;
//.........这里部分代码省略.........