static Uint64 calculate( size_t size, size_t vertexCount, const dataType* data ) { if (vertexCount < 4) { return 0; } typedef gmtl::Vec<dataType, 2> Vec; const dataType* v = data; Vec v1(v[0], v[1]); v += size; Vec v2(v[0], v[1]); v += size; Uint64 total = 0; for (size_t i = 2; (i + 1) < vertexCount; i += 2) { Vec v3(v[0], v[1]); v += size; Vec v4(v[0], v[1]); v += size; total += getTriangleArea(v1, v2, v3); total += getTriangleArea(v1, v3, v4); v1 = v3; v2 = v4; } return total; }
//------------------------------------------------------------------------------ double repo::core::RepoNodeMesh::getFaceArea(const unsigned int& index) const { double area = 0; const aiFace& face = faces->at(index); if (3 == face.mNumIndices || 4 == face.mNumIndices) { area = getTriangleArea(face, 0, 1, 2); if (face.mNumIndices == 4) // quadrilateral area += getTriangleArea(face, 0, 2, 3); } return area; }
void AbstractObject::prepareForSurfaceSampling(){ float areaValue = 0; for(uint i = 0; i < getTriangleNum(); i++){ areaValue += getTriangleArea(i); areaThreshold.push_back(areaValue); } boundArea = areaValue; }
void SceneObject::preprocessEmissionSampler() { totalArea = weight = 0.f; for(unsigned k=0; k<getTriangleNum(); k++) { totalArea += getTriangleArea(k); areaValues.push_back(totalArea); } weight = totalArea; }
static Uint64 calculate( size_t size, size_t vertexCount, const dataType* data ) { typedef gmtl::Vec<dataType, 2> Vec; const dataType* v = data; Uint64 total = 0; for (size_t i = 0; (i + 3) < vertexCount; i += 4) { Vec v1(v[0], v[1]); v += size; Vec v2(v[0], v[1]); v += size; Vec v3(v[0], v[1]); v += size; Vec v4(v[0], v[1]); v += size; total += getTriangleArea(v1, v2, v3); total += getTriangleArea(v1, v3, v4); } return total; }
void SceneObject::preprocessOtherSampler() { totalEnergy = 0.f; energyDensity.clear(); energyDensity.resize(getTriangleNum()); for (int i = 0; i < getTriangleNum(); i++) { energyDensity[i] = 0.f; areaValues.push_back(getTriangleArea(i)); } }
static Uint64 calculate( size_t size, size_t vertexCount, const dataType* data ) { typedef gmtl::Vec<dataType, 2> Vec; const dataType* v = data; Uint64 total = 0; for (size_t i = 0; (i + 2) < vertexCount; i += 3, v += size * 3) { total += getTriangleArea( Vec(v[size * 0], v[size * 0 + 1]), Vec(v[size * 1], v[size * 1 + 1]), Vec(v[size * 2], v[size * 2 + 1])); } return total; }
//-------------------------------------------------------------- void testApp::update(){ triangleReceiver.update(); // receive triangle data triangleReceiver.pulse.update(); list<Triangle*>::iterator triangleIt; for(triangleIt = triangleReceiver.triangles.begin(); triangleIt != triangleReceiver.triangles.end(); triangleIt++){ // set radius, center for every triangle (*triangleIt)->radius = getMaximumRadiusInTriangle((*triangleIt)->A, (*triangleIt)->B, (*triangleIt)->C); (*triangleIt)->center = getTriangleCenter((*triangleIt)->A, (*triangleIt)->B, (*triangleIt)->C); (*triangleIt)->lengthOfAB = (ofDist((*triangleIt)->A.x, (*triangleIt)->A.y, (*triangleIt)->B.x, (*triangleIt)->B.y)); // set linelengths (*triangleIt)->lengthOfBC = (ofDist((*triangleIt)->B.x, (*triangleIt)->B.y, (*triangleIt)->C.x, (*triangleIt)->C.y)); (*triangleIt)->lengthOfCA = (ofDist((*triangleIt)->C.x, (*triangleIt)->C.y, (*triangleIt)->A.x, (*triangleIt)->A.y)); (*triangleIt)->radius1 = (*triangleIt)->radius/5; (*triangleIt)->radius2 = ((*triangleIt)->radius/5)*2; (*triangleIt)->radius3 = ((*triangleIt)->radius/5)*3; (*triangleIt)->radius4 = ((*triangleIt)->radius/5)*4; (*triangleIt)->radius5 = (*triangleIt)->radius; cout << "AB: " << (*triangleIt)->lengthOfAB << endl; cout << "BC: " << (*triangleIt)->lengthOfBC << endl; cout << "CA: " << (*triangleIt)->lengthOfCA << endl; // enable or disable each of the 5 layers according to the area of the triangle float triangleArea = getTriangleArea((*triangleIt)->A, (*triangleIt)->B, (*triangleIt)->C); if(triangleArea < maximumAreaThreshold){ (*triangleIt)->state = TriangleStateDrawFirstLayer; } else if(triangleArea > maximumAreaThreshold && triangleArea < maximumAreaThreshold*2 ){ (*triangleIt)->state = TriangleStateDrawSecondLayer; } else if(triangleArea > maximumAreaThreshold*2 && triangleArea < maximumAreaThreshold*3){ (*triangleIt)->state = TriangleStateDrawThirdLayer; } else if(triangleArea > maximumAreaThreshold*3 && triangleArea < maximumAreaThreshold*4){ (*triangleIt)->state = TriangleStateDrawFourthLayer; } else{ (*triangleIt)->state = TriangleStateDrawFifthLayer; } } }
static Uint64 calculate( size_t size, size_t vertexCount, const dataType* data ) { if (vertexCount < 3) { return 0; } typedef gmtl::Vec<dataType, 2> Vec; const dataType* v = data; Vec first(v[0], v[1]); v += size; Vec last (v[0], v[1]); v += size; Uint64 total = 0; for (size_t i = 2; i < vertexCount; ++i) { Vec current(v[0], v[1]); v += size; total += getTriangleArea(first, last, current); last = current; } return total; }
static Uint64 calculate( size_t size, size_t vertexCount, const dataType* data ) { typedef gmtl::Vec<dataType, 2> Vec; const dataType* v = data; if (vertexCount < 3) { return 0; } Vec v0(v[0], v[1]); v += size; Vec v1(v[0], v[1]); v += size; Uint64 total = 0; for (size_t i = 2; i < vertexCount; i += 3, v += size * 3) { Vec v2(v[0], v[1]); total += getTriangleArea(v0, v1, v2); v0 = v1; v1 = v2; } return total; }
//----------------------------------------------------------------------------- int *Myron::globQuads(float minSideLength,float maxSideLength){ int i; float rads[4]; int w,h; MyronPoint p; MyronPoint middle; int tag; int accumCount=0; float xd; float yd; float *samples; int samplesCount = 0; int ii; w = this->imageWidth; h = this->imageHeight; unsigned char *globPixelListsCopy = new unsigned char[w*h]; #if defined(Macintosh) || defined(__CYGWIN__) for(int memcpycx=0;memcpycx<w*h;memcpycx++){ globPixelListsCopy[memcpycx]=globPixelLists[memcpycx]; } #else memcpy(globPixelListsCopy,globPixelLists,w*h); #endif samples = new float[w*h*3]; for(i=0;i<this->globPixelListsCount;i++){ tag = this->globPixelLists[i*3+2]; p.x = this->globPixelLists[i*3+0]; p.y = this->globPixelLists[i*3+1]; //this->pValueInterface->PointToValue(&p,&newval); if(tag==1){//beginning a glob //this->pMmList->NewListValue(&thisList); middle.x = (this->globBoxList[accumCount*4+0]+this->globBoxList[accumCount*4+2])/2; middle.y = (this->globBoxList[accumCount*4+1]+this->globBoxList[accumCount*4+3])/2; samplesCount = 0; } int foundOne = 0; // add a distance entry ONLY if this pixel is an edge. if( (p.x-1<0||p.y-1<0||p.x+1>=w||p.y+1>=h) ){//if this pixel is on the edge of the board then it is an edge. foundOne = 1; } else { //amongst the pixels off the edge of the image, there are more edge pixels for the glob. if( this->globPixelList[(p.y+1)*w+(p.x)]==0 || this->globPixelList[(p.y)*w+(p.x+1)]==0 || this->globPixelList[(p.y-1)*w+(p.x)]==0 || this->globPixelList[(p.y)*w+(p.x-1)]==0 ){ //if ANY of the neighbors is 0 foundOne = 1; } } if(foundOne){ //so add it to the list. xd = (float)p.x-(float)middle.x; yd = (float)p.y-(float)middle.y; samples[samplesCount*2+0] = (float)i; samples[samplesCount*2+1] = (float)sqrt(xd*xd+yd*yd); samplesCount++; } //this->pMmList->AppendValueToList(&thisList,&newval); if(tag==2){//ending a glob MyronPoint pp; MyronPoint pp2; float dist; float dist2; float ftmp; int itmp; //bubble sort them. int foundOne = 1; while(foundOne){ foundOne = 0; for(ii=0;ii<samplesCount-1;ii++){ pp.x = this->globPixelLists[(int)samples[ii*2+0]*3+0]; pp.y = this->globPixelLists[(int)samples[ii*2+0]*3+1]; pp2.x = this->globPixelLists[(int)samples[(ii+1)*2+0]*3+0]; pp2.y = this->globPixelLists[(int)samples[(ii+1)*2+0]*3+1]; dist = samples[ii*2+1]; dist2 = samples[(ii+1)*2+1]; if(dist2>dist){ //swap ftmp = dist; samples[ii*2+1] = dist2; samples[(ii+1)*2+1] = ftmp; itmp = pp.x; this->globPixelLists[(int)samples[ii*2+0]*3+0] = pp2.x; this->globPixelLists[(int)samples[(ii+1)*2+0]*3+0] = itmp; itmp = pp.y; this->globPixelLists[(int)samples[ii*2+0]*3+1] = pp2.y; this->globPixelLists[(int)samples[(ii+1)*2+0]*3+1] = itmp; foundOne = 1; } } } int quadPoints[4*2]; int ga_quadPoints[4*2]; float ga=0; for(int ci=(int)minSideLength;ci<maxSideLength;ci++){ //now start at the top of the stack and choose 4 points that are far enough apart. for(int qci=0;qci<4;qci++){ quadPoints[qci*2+0] = middle.x; quadPoints[qci*2+1] = middle.y; } int quadPointsCount = 0; for(ii=0;ii<samplesCount;ii++){ pp.x = this->globPixelLists[(int)samples[ii*2+0]*3+0]; pp.y = this->globPixelLists[(int)samples[ii*2+0]*3+1]; dist = samples[ii*2+1]; if(quadPointsCount==0){ //immediately add this first point. quadPoints[0] = pp.x; quadPoints[1] = pp.y; quadPointsCount++; } else if(quadPointsCount>3) { break; } else {//this is the middle, so compare to all of them int violated = 0; for(int iii=0;iii<quadPointsCount;iii++){ float xd = (float)quadPoints[iii*2+0] - pp.x; float yd =(float) quadPoints[iii*2+1] - pp.y; float d = (float)sqrt(xd*xd+yd*yd); //if(d<=minSideLength){ if(d<=ci){ violated = 1; } } if(violated==0){//then we found one that is away from all the others. quadPoints[quadPointsCount*2+0] = pp.x; quadPoints[quadPointsCount*2+1] = pp.y; quadPointsCount++; } } } //now that we have all the magic 4, rotate around and order them for(ii=0;ii<4;ii++){ rads[ii] = (float)atan2((float)quadPoints[ii*2+1]-middle.y,(float)quadPoints[ii*2+0]-middle.x); } //now bubble sort. foundOne = 1; while(foundOne){ foundOne = 0; for(int ii=0;ii<3;ii++){ if(rads[ii]<rads[ii+1]){ float tmp = rads[ii]; rads[ii] = rads[ii+1]; rads[ii+1] = tmp; tmp = (float)quadPoints[ii*2+0]; quadPoints[ii*2+0]=quadPoints[(ii+1)*2+0]; quadPoints[(ii+1)*2+0]=(int)tmp; tmp = (float)quadPoints[ii*2+1]; quadPoints[ii*2+1]=quadPoints[(ii+1)*2+1]; quadPoints[(ii+1)*2+1]=(int)tmp; foundOne = 1; } } } //now calculate the area of this quad. float area = getTriangleArea( (float)quadPoints[0],(float)quadPoints[1], (float)quadPoints[2],(float)quadPoints[3], (float)quadPoints[4],(float)quadPoints[5] ); area += getTriangleArea( (float)quadPoints[4],(float)quadPoints[5], (float)quadPoints[6],(float)quadPoints[7], (float)quadPoints[0],(float)quadPoints[1] ); //could this area be the biggest? if(area>ga){ //if so, copy to the thrown ga=area; for(int gi=0;gi<4*2;gi++){ ga_quadPoints[gi] = quadPoints[gi]; } } }//end looping through the area sampling phase. // MAKE A LIST OF 4 THEN APPEND IT TO RESULT LIST. //this->pMmList->NewListValue(&newval); for(int ica=0;ica<8;ica++){ this->globQuadList[accumCount*8+ica] = ga_quadPoints[ica]; } accumCount++; } } delete samples; #if defined(Macintosh) || defined(__CYGWIN__) for(int memcpycx=0;memcpycx<w*h;memcpycx++){ globPixelLists[memcpycx]=globPixelListsCopy[memcpycx]; } #else memcpy(globPixelLists,globPixelListsCopy,w*h); #endif delete globPixelListsCopy; return this->globQuadList; }
bool UvEdge::isIntersected(UvEdge& otherEdge) { // Check edge index if they have shared UV index bool isConnected; int& this_index_A = this->index.first; int& this_index_B = this->index.second; int& other_index_A = otherEdge.index.first; int& other_index_B = otherEdge.index.second; if (this_index_A == other_index_A || this_index_A == other_index_B) { isConnected = true; } else if (this_index_B == other_index_A || this_index_B == other_index_B) { isConnected = true; } else { isConnected = false; } float area1 = getTriangleArea( this->begin.u, this->begin.v, otherEdge.begin.u, otherEdge.begin.v, this->end.u, this->end.v); float area2 = getTriangleArea( this->begin.u, this->begin.v, otherEdge.end.u, otherEdge.end.v, this->end.u, this->end.v); float area3 = getTriangleArea( otherEdge.begin.u, otherEdge.begin.v, this->begin.u, this->begin.v, otherEdge.end.u, otherEdge.end.v); float area4 = getTriangleArea( otherEdge.begin.u, otherEdge.begin.v, this->end.u, this->end.v, otherEdge.end.u, otherEdge.end.v); float zero = 0.0; if (fabsf(zero - area1) <= FLT_EPSILON * fmaxf(1.f, fmaxf(fabsf(zero), fabsf(area1)))) { area1 = 0; } if (fabsf(zero - area2) <= FLT_EPSILON * fmaxf(1.f, fmaxf(fabsf(zero), fabsf(area2)))) { area2 = 0; } if (fabsf(zero - area3) <= FLT_EPSILON * fmaxf(1.f, fmaxf(fabsf(zero), fabsf(area3)))) { area3 = 0; } if (fabsf(zero - area4) <= FLT_EPSILON * fmaxf(1.f, fmaxf(fabsf(zero), fabsf(area4)))) { area4 = 0; } if (area1 == 0.0 && area2 == 0.0) { // If two edges are parallel on a same line Vector v1 = this->begin - otherEdge.begin; Vector v2 = this->end - otherEdge.begin; float d1 = v1.dot(v2); Vector v3 = this->begin - otherEdge.end; Vector v4 = this->end - otherEdge.end; float d2 = v3.dot(v4); if (d1 >= 0.0 and d2 >= 0.0) return false; else return true; } float ccw1; float ccw2; // If two edges are connected, at least 2 area of 4 triangles should be 0, // therefore, ccw1 and 2 need to be 0. if (isConnected) { ccw1 = 0; ccw2 = 0; } else { ccw1 = area1 * area2; ccw2 = area3 * area4; } if (ccw1 < 0 && ccw2 < 0) { return true; } else return false; }