示例#1
0
//--------------------------------------------------------------------------------------------------
/// Worker. Split the vertices that needs splitting and compact the vertexArray and indices.
//--------------------------------------------------------------------------------------------------
void TriangleVertexSplitter::splitVertices()
{
    CVF_ASSERT(!m_isComputed);
    m_isComputed = true;

    // Handle empty data;
    if (m_origTriangleIndices.size() == 0)
    {
        m_triangleIndices = new UIntArray;

        return;
    }

    size_t origVertexCount = m_origVertexArray.size();
    m_triangleIndices = new UIntArray(m_origTriangleIndices);

    m_vertexArray.reserve(origVertexCount);
    m_normalArray.reserve(origVertexCount);
    m_nextSplitVertexIdx.reserve(origVertexCount);

    m_origToUsedNodeMap.resize(origVertexCount);
    m_origToUsedNodeMap.setAll(UNDEFINED_UINT);

    size_t origConnIndex = 0;
    size_t numTris = m_triangleIndices->size() / 3;
    size_t tri;
    for (tri = 0; tri < numTris; tri++)
    {
        uint c0 = m_origTriangleIndices.val(origConnIndex);
        uint c1 = m_origTriangleIndices.val(origConnIndex + 1);
        uint c2 = m_origTriangleIndices.val(origConnIndex + 2);

        // Compute normal
        Vec3f v0 = m_origVertexArray.val(c0);
        Vec3f v1 = m_origVertexArray.val(c1);
        Vec3f v2 = m_origVertexArray.val(c2);

        Vec3f normal = (v1 - v0) ^ (v2 - v0);
        normal.normalize();

        uint newConn1 = processVertex(c0, normal);
        uint newConn2 = processVertex(c1, normal);
        uint newConn3 = processVertex(c2, normal);

        m_triangleIndices->set(origConnIndex, newConn1);
        m_triangleIndices->set(origConnIndex + 1, newConn2);
        m_triangleIndices->set(origConnIndex + 2, newConn3);

        origConnIndex += 3;
    }
}
示例#2
0
void TriMeshLoader::loadOBJ(const char* objfile,TriMesh* pmesh){
  fstream ifs;
  char line[LINE_SIZE];
  //cout << "READIING" << endl;
  char *tok;
  ifs.open(objfile);
  //cout << "REED" << endl;
  while(!ifs.eof()){
    //cout << "HEY LISTEN" << endl;
    ifs.getline(line,LINE_SIZE);
    //cout << "LISTEN HEY" << endl;
    //cout << line << endl;
    tok=strtok(line,TOK_SEPS);
    //cout << "BOOP" << endl;
    TokenPair *ptok=tokenMatch(tok);
    //cout << "POOB" << endl;
    if(ptok){
      switch(ptok->id){
        case T_VERT: processVertex(tok,pmesh); break;
        case T_FACE: processFace(tok,pmesh); break;
        default: /*processSkip(tok);*/ break;
      }
    }
  }
  //cout << "FINISHED READING" << endl;
  ifs.close();
}
示例#3
0
Boolean FrTreeNode::walk(void){
	switch(entryPoint){
		case firstVertex:
			if(v==ZERO)nodeErr(4);
			if(v->Qideal())nodeErr(11);
			startUp();	
			virginVertex(v->bv);
			entryPoint=nextVertex;
		case nextVertex:
			return(processVertex());
		case firstEdge:
			// Create the first admissible edge, if it exists.
			// if there is no admissible edge, control flows to nextVertex
			
			v->e=0;
			entryPoint=nextEdge;
			
			// control flows to next case
			
		case nextEdge:
			if(((FrTree*)v)->eNext()){
				v->V();
				virginVertex(v->cv);
				return(TRUE);
			}
			else{
				entryPoint=nextVertex;
				return(TRUE);
			}
		default: nodeErr(6);
	}
	nodeErr(8);
}
 void process() {
     for(Vertex *v:graph->vertices) {
         vertexMarks[v]=VACANT;      //mark all vertices as vacant
         for(Edge *e:v->getOutEdges()) {
             edgeToReduce[e]=false;  //mark all edges as don't_reduce
         }
     }
     for(Vertex *v:graph->vertices) {
         processVertex(v);//process all vertices
     }
     std::cout <<"Transitive removed:" <<count1 << "\n";
     std::cout <<"Short removed:" <<count2 << "\n";
     removeReducedEdges();
 }
示例#5
0
void processLine( const char *line )
{
  char temp[256];
  strcpy( temp, line );

  char *token   = strtok( temp, " " );

  if( strcmp( token, "v" ) == 0 )
  { 
    processVertex( line );
  }
  else if( strcmp( token, "vn" ) == 0 )
  { 
    processNormal( line );
  }
  else if( strcmp( token, "vt" ) == 0 )
  {
    processTexture( line ); 
  }
  else if( strcmp( token, "f" ) == 0 )
  { 
    processFace( line );
  }
}
示例#6
0
Boolean FcloneNode::walk(void){
	switch(entryPoint){
		case firstVertex:
			if(v==ZERO)nodeErr(4);
			if(v->Qideal())nodeErr(11);
			startUp();	
			virginCloneVertex(v->bv,vClone->bv);
			entryPoint=nextVertex;
		//control flows directly to GLrun
		case nextVertex:
			return(processVertex());
		case firstEdge:{
			// Process the first edge, if there is one.
			// if there is no defined edge, control flows to GLnextVertex
			
			Ptr DEREF=v&v->bv;
			GLref startRef;
			v->xGetPacketRef(startRef,GLr,DEREF);
			v-v->bv;
			if(isNull(startRef)){
				entryPoint=nextVertex;  // no real link
				return(TRUE);  
			}
			
			// start search for first edge at the very beginning
			GLref entryPacketRef;
			v->xsetToFirstPacket(entryPacketRef,startRef);  

			if(itsStepper->firstEdge(entryPacketRef)){
				// first edge detected
				GLref ref;
				v->xEdgeEntryToOwner(ref,itsStepper->refDatum);
				v->cv=ref;
				entryPoint=nextEdge; 
				return(processEdge()); 
			}
			else{	
				// real link has no edges
				
				entryPoint=nextVertex; 
				return(TRUE);  
			}
		}
		case nextEdge:{
			if(itsStepper->nextEdge()){
				// next edge detected
				GLref ref;
				v->xEdgeEntryToOwner(ref,itsStepper->refDatum);
				v->cv=ref;
				entryPoint=nextEdge; 
				return(processEdge()); 
			}
			else{	
				// real link has no more edges
				
				entryPoint=nextVertex; 
				return(TRUE);  
			}

		}
		default: nodeErr(6);
	}
	nodeErr(8);
}
示例#7
0
Boolean FTTdriverNode::walk(void){

// the following code is identical to that of FGLwalkNode::walk().
// We need to repeat it here so that FTTdriverNode overriding
// subroutines virginVertex and processEdge will be called
//
// Is there a more elegant solution that doesn't require 
// code  replication?

	switch(entryPoint){
		case firstVertex:
			if(v==ZERO)nodeErr(4);
			if(v->Qideal())nodeErr(11);
// OUTPUT DISPLAY
//@rn			tout <= "*** pass " <= pTree->passNumber <=" ***" <= "\n";
//@rn ask me if I care
// END OUTPUT DISPLAY
			startUp();
			virginVertex(v->bv);
			entryPoint=nextVertex;
		case nextVertex:
			return(processVertex());
		case firstEdge:{
			// Process the first edge, if there is one.
			// if there is no defined edge, control flows to GLnextVertex
			
			Ptr DEREF=v&v->bv;
			GLref startRef;
			v->xGetPacketRef(startRef,GLr,DEREF);
			v-v->bv;
			if(isNull(startRef)){
				entryPoint=nextVertex;  // no real link
				return(TRUE);  
			}
			
			// start search for first edge at the very beginning
			GLref entryPacketRef;
			v->xsetToFirstPacket(entryPacketRef,startRef);  
			if(itsStepper->firstEdge(entryPacketRef)){
				// first edge detected
				GLref ref;
				v->xEdgeEntryToOwner(ref,itsStepper->refDatum);
				v->cv=ref;
				entryPoint=nextEdge; 
				return(processEdge()); 
			}
			else{	
				// real link has no edges
				
				entryPoint=nextVertex; 
				return(TRUE);  
			}
		}
		case nextEdge:{
			if(itsStepper->nextEdge()){
				// next edge detected
				GLref ref;
				v->xEdgeEntryToOwner(ref,itsStepper->refDatum);
				v->cv=ref;
				entryPoint=nextEdge; 
				return(processEdge()); 
			}
			else{	
				// real link has no more edges
				
				entryPoint=nextVertex; 
				return(TRUE);  
			}

		}
		default: nodeErr(6);
	}
	nodeErr(8);
}
示例#8
0
LimaStatusCode GreedyPosTagger::process(
  AnalysisContent& analysis) const
{

  // start postagging here !
  TimeUtils::updateCurrentTime();
  PTLOGINIT;
  LINFO << "start greedy posTagging";

  AnalysisGraph* anagraph=static_cast<AnalysisGraph*>(analysis.getData("AnalysisGraph"));
  
  AnalysisGraph* posgraph=new AnalysisGraph("PosGraph",m_language,false,true,*anagraph);

  // walk on the vertex but don't process a vertex if one
  // of its predecessor hasn't been processed.
  LinguisticGraph* graph=posgraph->getGraph();
  LinguisticGraphVertex endVx=posgraph->lastVertex();

  map<LinguisticGraphVertex,uint64_t> processed;
  set<LinguisticGraphVertex> toProcess;
  toProcess.insert(anagraph->firstVertex());
  set<LinguisticGraphVertex> nextToProcess;
  set<LinguisticGraphVertex>::iterator toProcessItr;
  map<LinguisticGraphVertex,uint64_t>::iterator processedItr;
  LinguisticGraphInEdgeIt inItr,inItrEnd;
  LinguisticGraphOutEdgeIt outItr,outItrEnd;

  while (toProcess.size()!=0)
  {

    //cout << "toProcess is ";
    //        copy(toProcess.begin(),toProcess.end(),ostream_iterator<LinguisticGraphVertex>(cout,","));
    //        cout << endl;

    for (toProcessItr=toProcess.begin();
         toProcessItr!=toProcess.end();
         toProcessItr++)
    {

      // process vertex
      processVertex(*toProcessItr,anagraph);
      processed.insert(make_pair(*toProcessItr,out_degree(*toProcessItr,*graph)));
      //cerr << "processed : insert " << *toProcessItr << " with " << out_degree(*toProcessItr,*graph) << endl;

      // remove processed if necessary
      boost::tie(inItr,inItrEnd)=in_edges(*toProcessItr,*graph);
      for (;inItr!=inItrEnd;inItr++)
      {
        processedItr=processed.find(source(*inItr,*graph));
        processedItr->second--;
        //cerr << "processed : vertex " << processedItr->first << " decremented to " << processedItr->second << endl;
        if (processedItr->second==0)
        {
          //cerr << "processed : remove " << processedItr->first << endl;
          processed.erase(processedItr);
        }
      }

      // check and add nex vertex to process
      boost::tie(outItr,outItrEnd)=out_edges(*toProcessItr,*graph);
      for (;outItr!=outItrEnd;outItr++)
      {
        LinguisticGraphVertex next=target(*outItr,*graph);
        if (next==endVx)
        {
          continue;
        }
        // check if all in vertices have been processed
        boost::tie(inItr,inItrEnd)=in_edges(next,*graph);
        bool ok=true;
        for (;inItr!=inItrEnd;inItr++)
        {
          if (processed.find(source(*inItr,*graph))==processed.end())
          {
            ok=false;
            break;
          }
        }
        if (ok)
        {
          nextToProcess.insert(next);
        }
      }

    }

    toProcess.clear();
    toProcess.swap(nextToProcess);

  }

  TimeUtils::logElapsedTime("GreedyPosTagger");
  return SUCCESS_ID;
}