void FractalProjector:: new_vertex(Vertex* vrt, Face* parent) { // set the vertex to the center by calling the parents method RefinementCallbackLinear<APosition>::new_vertex(vrt, parent); // calculate the normal of the face vector3 n; CalculateNormal(n, parent, m_aaPos); // we have to alter the length. // first scale it to the average length of the faces edges, // then scale it with the given scaleFac. number avLen = 0; size_t numVrts = parent->num_vertices(); for(size_t i = 0; i < numVrts; ++i){ avLen += VecDistance(m_aaPos[parent->vertex(i)], m_aaPos[parent->vertex((i+1)% numVrts)]); } avLen /= (number)numVrts; VecScale (n, n, m_scaleFac * avLen); // offset the vertex by the calculated normal VecAdd(m_aaPos[vrt], m_aaPos[vrt], n); }
void FractalProjector:: new_vertex(Vertex* vrt, Edge* parent) { // set the vertex to the center by calling the parents method RefinementCallbackLinear<APosition>::new_vertex(vrt, parent); // calculate the normal of the edge vector3 n; CalculateNormal(n, *m_pGrid, parent, m_aaPos); // first scale it to the same length as the edge, then scale it with the // given scaleFac number len = VecDistance(m_aaPos[parent->vertex(0)], m_aaPos[parent->vertex(1)]); VecScale (n, n, m_scaleFac * len); // offset the vertex by the calculated normal VecAdd(m_aaPos[vrt], m_aaPos[vrt], n); }
int FindVertexByCoordinate(const MathVector<dim>& coord, size_t ncoords, const MathVector<dim> vCoords[]) { if (ncoords <= 0) return -1; size_t bestVrt = 0; number bestDistSq = VecDistanceSq(coord, vCoords[0]); for (size_t i=1; i<ncoords; ++i) { number distSq = VecDistance(coord, vCoords[i]); if(distSq < bestDistSq) { bestDistSq = distSq; bestVrt = i; } } return bestVrt; }
CyVOID NonLinerPartition( FeatureSeq *pFeaSeq, CyINT16 partitionNum ) { CyINT16 i, j; CyFLOAT diff[MAX_FRAMES]={0}; // 若特征数量小于状态数 if( pFeaSeq->dFeaCounter < NLP_N) { } // Step 1: 计算特征参数变化量,并累加 for (i=1; i< pFeaSeq->dFeaCounter; i++) { diff[i] = diff[i-1] + VecDistance(pFeaSeq->feature[i], pFeaSeq->feature[i-1]); } // 用diff[0]来存储平均总变化量 *diff = diff[i-1]/(CyFLOAT)partitionNum; // Step 2: 计算每个块的分界点 pFeaSeq->iNlpParam[0] = 0; // 第一个分界点是第0帧 for (i=1, j=1; i<pFeaSeq->dFeaCounter; i++) { if ( diff[i]>diff[0]*j ) // 式(2.41) { pFeaSeq->iNlpParam[j++] = i; if(j>=partitionNum) break; } } // 最后一个分界点是最后一帧 pFeaSeq->iNlpParam[partitionNum] = pFeaSeq->dFeaCounter; }
number VertexDistance(Vertex* v0, Vertex* v1, TAAPos& aaPos) { return VecDistance(aaPos[v0], aaPos[v1]); }