void BookAR::updateData(const ci::Surface32f& image, gl::VboMesh& mesh, float max_height)
{
	uint32_t book_w = image.getWidth();
	uint32_t book_h = image.getHeight();

	if (!mesh || mesh.getNumVertices() != book_w * book_h)
	{//needs refresh
		gl::VboMesh::Layout layout;
		layout.setDynamicColorsRGB();
		layout.setDynamicPositions();
		_mesh_book = gl::VboMesh( book_w * book_h, 0, layout, GL_POINTS );
	}
	Surface32f::ConstIter pixelIter = image.getIter();
	gl::VboMesh::VertexIter vertexIter( mesh );

	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );

			// the x and the z coordinates correspond to the pixel's x & y
			float x = pixelIter.x() - book_h / 2.0f;
			float z = pixelIter.y() - book_h / 2.0f;

			vertexIter.setPosition( x, height * max_height, z );
			vertexIter.setColorRGB( color );
			++vertexIter;
		}
	}
}
Exemple #2
0
const ID &
SimpleNumberer::number(Graph &theGraph, int lastVertex)
{
    // first check our size, if not same make new
    
    if (numVertex != theGraph.getNumVertex()) {

	if (theRefResult != 0)
	    delete theRefResult;
	
	numVertex = theGraph.getNumVertex();
	theRefResult = new ID(numVertex);

	if (theRefResult == 0) {
	    opserr << "ERROR:  SimpleNumberer::number - Out of Memory\n";
	    theRefResult = new ID(0);
	    numVertex = 0;
	    return *theRefResult;
	}
    }

    // see if we can do quick return
    
    if (numVertex == 0) 
	return *theRefResult;
	    

    // Now we go through the iter and assign the numbers

    if (lastVertex != -1) {
	opserr << "WARNING:  SimpleNumberer::number -";
	opserr << " - does not deal with lastVertex";
    }
    
    Vertex *vertexPtr;
    VertexIter &vertexIter = theGraph.getVertices();
    int count = 0;
    
    while ((vertexPtr = vertexIter()) != 0) {

	(*theRefResult)(count++) = vertexPtr->getTag();
	vertexPtr->setTmp(count);
    }
    
    return *theRefResult;
}
Exemple #3
0
MStatus tm_randPoint::undoIt()
{
	if(helpMode) return MS::kSuccess;
	if(selVtxMode)
	{
		MSelectionList curSel;
		MGlobal::getActiveSelectionList( curSel);
		MItSelectionList iter( curSel, MFn::kMeshVertComponent);
		MObject component;
		MDagPath selVtx_dagPath;
		int vtxCount = 0;
		for ( ; !iter.isDone(); iter.next() )
		{
			iter.getDagPath(selVtx_dagPath, component);
			MItMeshVertex vertexIter( selVtx_dagPath, component );
			for ( ; !vertexIter.isDone(); vertexIter.next() )
			{
				vertexIter.setPosition( oldPointsArrays[0][vtxCount], MSpace::kObject );
				vtxCount++;
			}
		}
	}
	else
	{
		int num_meshes = res_MDagPathArray.length();
		for( int i = 0; i < num_meshes; i++ )
		{
			MDagPath dagPath = res_MDagPathArray[i];
			MObject node;

			node = dagPath.node();
			MFnDependencyNode fnNode( node );
			
			MStatus polyStatus;
			MFnMesh fnMesh( node, &polyStatus );
			if( polyStatus == MS::kSuccess )
			{
				MStatus status;
				status = fnMesh.setPoints( oldPointsArrays[i]);
				if (!status){status.perror("### error setting point ::undoIt()");return status;}
			}
		}
	}
	return MS::kSuccess;
}
MStatus convertVerticesToContainedEdgesCommand::redoIt()

{

   MSelectionList finalEdgesSelection;

   MDagPath meshDagPath;

   MObject multiVertexComponent, singleVertexComponent;

   int dummyIndex;



   // ITERATE THROUGH EACH "VERTEX COMPONENT" THAT IS CURRENTLY SELECTED:

   for (MItSelectionList vertexComponentIter(previousSelectionList, MFn::kMeshVertComponent); !vertexComponentIter.isDone(); vertexComponentIter.next())

   {

      // STORE THE DAGPATH, COMPONENT OBJECT AND MESH NAME OF THE CURRENT VERTEX COMPONENT:

      vertexComponentIter.getDagPath(meshDagPath, multiVertexComponent);

      MString meshName = meshDagPath.fullPathName();



      // VERTEX COMPONENT HAS TO CONTAIN AT LEAST ONE VERTEX:

      if (!multiVertexComponent.isNull())

      {

         // ITERATE THROUGH EACH "VERTEX" IN THE CURRENT VERTEX COMPONENT:

         for (MItMeshVertex vertexIter(meshDagPath, multiVertexComponent); !vertexIter.isDone(); vertexIter.next())

         {

            // FOR STORING THE EDGES CONNECTED TO EACH VERTEX:

            MIntArray connectedEdgesIndices;

            vertexIter.getConnectedEdges(connectedEdgesIndices);



            // ITERATE THROUGH EACH EDGE CONNECTED TO THE CURRENT VERTEX:

            MItMeshEdge edgeIter(meshDagPath);

            for (unsigned i=0; i<connectedEdgesIndices.length(); i++)

            {

               // FIND AND STORE THE *FIRST* "END VERTEX" OF THE CURRENT EDGE:

               edgeIter.setIndex(connectedEdgesIndices[i], dummyIndex);

               MSelectionList singleVertexList;

               MString vertexName = meshName;

               vertexName += ".vtx[";

               vertexName += edgeIter.index(0);

               vertexName += "]";

               singleVertexList.add(vertexName);

               singleVertexList.getDagPath(0, meshDagPath, singleVertexComponent);

               // SEE WHETHER THE VERTEX BELONGS TO THE ORIGINAL SELECTION, AND IF IT DOES PROCEED TO CHECK NEXT END VERTEX:

               if (!singleVertexComponent.isNull() && previousSelectionList.hasItem(meshDagPath, singleVertexComponent))

               {

                  // FIND AND STORE THE *SECOND* "END VERTEX" OF THE CURRENT EDGE:

                  singleVertexList.clear();

                  vertexName = meshName;

                  vertexName += ".vtx[";

                  vertexName += edgeIter.index(1);

                  vertexName += "]";

                  singleVertexList.add(vertexName);

                  singleVertexList.getDagPath(0, meshDagPath, singleVertexComponent);

                  // SEE WHETHER THE VERTEX BELONGS TO THE ORIGINAL SELECTION, AND IF IT DOES, ADD THE EDGE TO THE FINAL CONTAINED EDGES LIST:

                  if (!singleVertexComponent.isNull() && previousSelectionList.hasItem(meshDagPath, singleVertexComponent))

                  {

                     MString edgeName = meshName;

                     edgeName += ".e[";

                     edgeName += connectedEdgesIndices[i];

                     edgeName += "]";

                     finalEdgesSelection.add(edgeName);

                  }

               }

            }

         }

      }

   }



   // FINALLY, MAKE THE NEW "CONTAINED EDGES", THE CURRENT SELECTION:

   MGlobal::setActiveSelectionList(finalEdgesSelection, MGlobal::kReplaceList);



   // RETURN NEW CONTAINED EDGES LIST FROM THE MEL COMMAND, AS AN ARRAY OF STRINGS:

   MStringArray containedEdgesArray;

   finalEdgesSelection.getSelectionStrings(containedEdgesArray);

   MPxCommand::setResult(containedEdgesArray);



   return MS::kSuccess;

}
Exemple #5
0
MStatus tm_randPoint::doIt( const MArgList& args )
{
	MStatus stat = MS::kSuccess;
	double amp = 1.0;
	double amp_x = 1.0;
	double amp_y = 1.0;
	double amp_z = 1.0;
	unsigned int seed = 0;
	bool useAxisAmp = false;
	bool exactObject = false;
	unsigned int num_meshes;
	MString objMString;
	helpMode = false;

	MArgDatabase argData( syntax(), args);
	if(argData.isFlagSet( help_Flag))
	{
		helpMode = true;
		appendToResult( "\n// tm_polygon randPoint usage:\n");
		appendToResult( "//    Command operates with specified object with \"-obj\" flag,\n");
		appendToResult( "//       if this flag is not set, command use selected poly objects or poly vertices.\n");
		appendToResult( "//    Synopsis: tm_polygon [flags].\n");
		appendToResult( "//    Type \"help tm_randPoint\" to query flags.\n");
		return MS::kSuccess;
	}
	if(argData.isFlagSet( amp_Flag))
		argData.getFlagArgument( amp_Flag, 0, amp);
	if(argData.isFlagSet( ampX_Flag))
	{
		argData.getFlagArgument( ampX_Flag, 0, amp_x);
		useAxisAmp = true;
	}
	if(argData.isFlagSet( ampY_Flag))
	{
		argData.getFlagArgument( ampY_Flag, 0, amp_y);
		useAxisAmp = true;
	}
	if(argData.isFlagSet( ampZ_Flag))
	{
		argData.getFlagArgument( ampZ_Flag, 0, amp_z);
		useAxisAmp = true;
	}
	if(argData.isFlagSet( seed_Flag))
		argData.getFlagArgument( seed_Flag, 0, seed);
	if(argData.isFlagSet( obj_Flag))
	{
		exactObject = true;
		argData.getFlagArgument( obj_Flag, 0, objMString);
	}

   double randMax = (double)RAND_MAX;
   double halfRandMax = 0.5 * randMax;


	unsigned i;
    if( exactObject)
	{
		selVtxMode = false;
		MSelectionList m_selList;
		MDagPath m_dagPath;
		stat = m_selList.add( objMString);
		if (!stat){stat.perror("###1 invalid obect path string");return stat;}
		stat = m_selList.getDagPath( 0, m_dagPath);
		if (!stat){stat.perror("###2 invalid obect path string");return stat;}
		stat = res_MDagPathArray.append( m_dagPath);
		if (!stat){stat.perror("###3 invalid obect path string");return stat;}
	}
	else
	{
		MSelectionList curSel;
		MGlobal::getActiveSelectionList( curSel);
		unsigned int numSelected = curSel.length();
		MItSelectionList iter( curSel, MFn::kMeshVertComponent);
		if (iter.isDone())
		{
			selVtxMode = false;
			MItDag::TraversalType traversalType = MItDag::kBreadthFirst;
			MFn::Type filter = MFn::kMesh;
			MItDag mit_dag( traversalType, filter, &stat);
			for( i = 0; i < numSelected; i++ )
			{
				MDagPath sel_dagPath;
				curSel.getDagPath( i, sel_dagPath);
				stat = mit_dag.reset( sel_dagPath,  traversalType, filter);
				if ( !stat) { stat.perror("MItDag constructor");return stat;}
				for ( ; !mit_dag.isDone(); mit_dag.next() )
				{
					MDagPath m_dagPath;
					stat = mit_dag.getPath(m_dagPath);
					if ( !stat ) { stat.perror("MItDag::getPath error"); continue;}
					stat = res_MDagPathArray.append( m_dagPath);
					if ( !stat ) { stat.perror("MDagPathArray.append error"); continue;}
				}
			}
		}
		else
		{
			newPointsArrays = new MPointArray[1];
			oldPointsArrays = new MPointArray[1];
			selVtxMode = true;
			MObject component;
			MDagPath selVtx_dagPath;
			for ( ; !iter.isDone(); iter.next() )
			{
				iter.getDagPath(selVtx_dagPath, component);
				MItMeshVertex vertexIter( selVtx_dagPath, component );
				for ( ; !vertexIter.isDone(); vertexIter.next() )
				{
					MPoint oldPoint = vertexIter.position(MSpace::kObject );
					MPoint newPoint;
					newPoint.x = oldPoint.x + ((halfRandMax - (double)rand()) / randMax) * amp * amp_x;
					newPoint.y = oldPoint.y + ((halfRandMax - (double)rand()) / randMax) * amp * amp_y;
					newPoint.z = oldPoint.z + ((halfRandMax - (double)rand()) / randMax) * amp * amp_z;
					oldPointsArrays[0].append( oldPoint);
					newPointsArrays[0].append( newPoint);
				}
			}
		}
	}

	if(!selVtxMode)
	{
		num_meshes = res_MDagPathArray.length();
		newPointsArrays = new MPointArray[num_meshes];
		oldPointsArrays = new MPointArray[num_meshes];
		for( i = 0; i < num_meshes; i++ )
		{
			MDagPath dagPath = res_MDagPathArray[i];
			MObject node;

			node = dagPath.node();
			MFnDependencyNode fnNode( node );
			
			MStatus polyStatus;
			MFnMesh fnMesh( node, &polyStatus );

			if( polyStatus == MS::kSuccess )
			{
				MStatus status;
				status = fnMesh.getPoints( oldPointsArrays[i]);
				if (!status){status.perror("### error getting mesh points");return stat;}
				unsigned int numVertices = oldPointsArrays[i].length();
				newPointsArrays[i].setLength(numVertices);
				oldPointsArrays[i].setLength(numVertices);
				if(seed != 0) srand(seed);
				if(useAxisAmp)
				{
					for( unsigned int v = 0; v < numVertices; v++)
					{
						newPointsArrays[i][v].x = oldPointsArrays[i][v].x + ((halfRandMax - (double)rand()) / randMax) * amp * amp_x;
						newPointsArrays[i][v].y = oldPointsArrays[i][v].y + ((halfRandMax - (double)rand()) / randMax) * amp * amp_y;
						newPointsArrays[i][v].z = oldPointsArrays[i][v].z + ((halfRandMax - (double)rand()) / randMax) * amp * amp_z;
					}
				}
				else
				{
					for( unsigned int v = 0; v < numVertices; v++)
					{
						newPointsArrays[i][v].x = oldPointsArrays[i][v].x + ((halfRandMax - (double)rand()) / randMax) * amp;
						newPointsArrays[i][v].y = oldPointsArrays[i][v].y + ((halfRandMax - (double)rand()) / randMax) * amp;
						newPointsArrays[i][v].z = oldPointsArrays[i][v].z + ((halfRandMax - (double)rand()) / randMax) * amp;
					}
				}
			}
			else stat = MS::kFailure;
		}
	}
	return redoIt();
}
Exemple #6
0
MStatus cvPos::doIt( const MArgList& args )
{

    MString componentName;
	MSpace::Space transformSpace = MSpace::kWorld;

	for (unsigned int i = 0; i < args.length (); i++)
	{
		MString argStr;
		args.get (i, argStr);
		if (MString ("-l") == argStr || MString ("-local") == argStr)
			transformSpace = MSpace::kObject;
		else if (MString ("-w") == args.asString (i) ||
				 MString ("-world") == argStr)
			transformSpace = MSpace::kWorld;
		else
			componentName = argStr;
	}

    MObject     component;
    MDagPath    dagPath;

	if (!componentName.length ()) {
		MSelectionList activeList;

		MGlobal::getActiveSelectionList (activeList);

		MItSelectionList iter (activeList, MFn::kComponent);
		if (iter.isDone ())	{
			displayError ("No components selected");
			return MS::kFailure;
		} else {
			iter.getDagPath (dagPath, component);
			iter.next ();
			if (!iter.isDone ()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
		}
	} else {
		MSelectionList list;

		if (! list.add( componentName ) ) {
			componentName += ": no such component";
			displayError(componentName);
			return MS::kFailure; // no such component
		}
		MItSelectionList iter( list );
        iter.getDagPath( dagPath, component );
	}

	if (component.isNull()) {
		displayError("not a component");
		return MS::kFailure;
	}

	switch (component.apiType()) {
	case MFn::kCurveCVComponent:
		{
			MItCurveCV curveCVIter( dagPath, component );
			point = curveCVIter.position(transformSpace );
			curveCVIter.next();
			if (!curveCVIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	case MFn::kSurfaceCVComponent:
		{
			MItSurfaceCV surfCVIter( dagPath, component, true );
			point = surfCVIter.position(transformSpace );
			surfCVIter.next();
			if (!surfCVIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	case MFn::kMeshVertComponent:
		{
			MItMeshVertex vertexIter( dagPath, component );
			point = vertexIter.position(transformSpace );
			vertexIter.next();
			if (!vertexIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	default:
		cerr << "Selected unsupported type: (" << component.apiType()
			 << "): " << component.apiTypeStr() << endl;
	}

    return redoIt();
}
Exemple #7
0
const ID &
MyRCM::number(Graph &theGraph, int startVertex)
{
    // first check our size, if not same make new
    
    if (numVertex != theGraph.getNumVertex()) {

	// delete the old
	if (theRefResult != 0)
	    delete theRefResult;
	
	numVertex = theGraph.getNumVertex();
	theRefResult = new ID(numVertex);

	if (theRefResult == 0) {
	    opserr << "ERROR:  MyRCM::number - Out of Memory\n";
	    theRefResult = new ID(0);
	    numVertex = 0;
	    return *theRefResult;
	}
    }

    // see if we can do quick return
    
    if (numVertex == 0) 
	return *theRefResult;
	    

    // we first set the Tmp of all vertices to -1, indicating
    // they have not yet been added.
    
    Vertex *vertexPtr;
    VertexIter &vertexIter = theGraph.getVertices();
    
    while ((vertexPtr = vertexIter()) != 0)
	vertexPtr->setTmp(-1);

    // we now set up; setting our markers and getting first vertex
    if (startVertex != -1)
	startVertexTag = startVertex;
    
    if (startVertexTag != -1) {
	vertexPtr = theGraph.getVertexPtr(startVertexTag);
	if (vertexPtr == 0) {
	    opserr << "WARNING:  MyRCM::number - No vertex with tag ";
	    opserr << startVertexTag << "Exists - using first come from iter\n";
	    startVertexTag = -1;
	}
    }	

    // if no starting vertex use the first one we get from the VertexIter
    
    VertexIter &vertexIter2 = theGraph.getVertices();    
    if (startVertexTag == -1) 
	vertexPtr = vertexIter2();

    int currentMark = numVertex-1;  // marks current vertex visiting.
    int nextMark = currentMark -1;  // indiactes where to put next Tag in ID.
    (*theRefResult)(currentMark) = vertexPtr->getTag();
    vertexPtr->setTmp(currentMark);

    // we continue till the ID is full

    while (nextMark >= 0) {

	// get the current vertex and its adjacency
	
	vertexPtr = theGraph.getVertexPtr((*theRefResult)(currentMark));
	const ID &adjacency = vertexPtr->getAdjacency();

	// go through the vertices adjacency and add vertices which
	// have not yet been Tmp'ed to the (*theRefResult)

	int size = adjacency.Size();
	for (int i=0; i<size; i++) {
	    
	    int vertexTag = adjacency(i);
	    vertexPtr = theGraph.getVertexPtr(vertexTag);
	    if ((vertexPtr->getTmp()) == -1) {
		vertexPtr->setTmp(nextMark);
		(*theRefResult)(nextMark--) = vertexTag;
	    }
	}

	// go to the next vertex
	//  we decrement because we are doing reverse Cuthill-McKee
	
	currentMark--;

	// check to see if graph is disconneted
	
	if ((currentMark == nextMark) && (currentMark >= 0)) {
	    opserr << "WARNING:  MyRCM::number - Disconnected graph\n";
	    
	    // loop over iter till we get a vertex not yet Tmped
	    
	    while (((vertexPtr = vertexIter2()) != 0) && 
		   (vertexPtr->getTmp() != -1)) 
		;
	    
	    nextMark--;
	    vertexPtr->setTmp(currentMark);
	    (*theRefResult)(currentMark) = vertexPtr->getTag();
	}

    }
    
    // now set the vertex references instead of the vertex tags
    // in the result, we change the Tmp to indicate number and return
    
    for (int i=0; i<numVertex; i++) {
	int vertexTag = (*theRefResult)(i);
	vertexPtr = theGraph.getVertexPtr(vertexTag);
	vertexPtr->setTmp(i+1); // 1 through numVertex
	(*theRefResult)(i) = vertexPtr->getTag();
    }

    theGraph.Print(opserr, 3);
    opserr << *theRefResult;
    return *theRefResult;
}
Exemple #8
0
const ID &
MyRCM::number(Graph &theGraph, const ID &startVertices)
{
    // first check our size, if not same make new
    
    if (numVertex != theGraph.getNumVertex()) {

	// delete the old
	if (theRefResult != 0)
	    delete theRefResult;
	
	numVertex = theGraph.getNumVertex();
	theRefResult = new ID(numVertex);

	if (theRefResult == 0) {
	    opserr << "ERROR:  MyRCM::number - Out of Memory\n";
	    theRefResult = new ID(0);
	    numVertex = 0;
	    return *theRefResult;
	}
    }

    // see if we can do quick return
    
    if (numVertex == 0) 
	return *theRefResult;

    ID copyStart(startVertices);

    // we determine which node to start with
    int minStartVertexTag =0;
    int minAvgProfile = 0;
    int startVerticesSize = startVertices.Size();
    
    for (int j=0; j<startVerticesSize; j++) {
	// we first set the Tmp of all vertices to -1, indicating
	// they have not yet been added.
    
	Vertex *vertexPtr;
	VertexIter &vertexIter = theGraph.getVertices();
    
	while ((vertexPtr = vertexIter()) != 0)
	    vertexPtr->setTmp(-1);

	// we now set up; setting our markers and set first vertices
	VertexIter &vertexIter2 = theGraph.getVertices();    
	int currentMark = numVertex-1;  // marks current vertex visiting.
	int nextMark = currentMark-1;

	for (int k=0; k<startVerticesSize; k++)
	    if (k != j)
		copyStart(k) = 0;
	    else	
		copyStart(k) = 1;
	
	vertexPtr = theGraph.getVertexPtr(startVertices(j));	
	(*theRefResult)(currentMark) = vertexPtr->getTag();
	vertexPtr->setTmp(currentMark);

	int numFromStart = 1;
	int avgProfile = 1;	
	while (numFromStart < startVerticesSize) {
	    // get the current vertex and its adjacency

	    vertexPtr = theGraph.getVertexPtr((*theRefResult)(currentMark));
	    const ID &adjacency = vertexPtr->getAdjacency();

	    // go through the vertices adjacency and add vertices which
	    // have not yet been Tmp'ed to the (*theRefResult)

	    int size = adjacency.Size();
	    for (int i=0; i<size; i++) {
		int vertexTag = adjacency(i);
		int loc =startVertices.getLocation(vertexTag);
		if (loc >= 0) {
		    vertexPtr = theGraph.getVertexPtr(vertexTag);
		    if ((vertexPtr->getTmp()) == -1) {
			vertexPtr->setTmp(nextMark);
			copyStart(loc) = 1;
			numFromStart++;
			avgProfile += currentMark - nextMark;			
			(*theRefResult)(nextMark--) = vertexTag;
		    }
		}
	    }

	    // go to the next vertex
	    //  we decrement because we are doing reverse Cuthill-McKee
	
	    currentMark--;

	    // check to see if graph is disconneted
	
	    if (currentMark == nextMark && numFromStart < startVerticesSize) {
		// loop over iter till we get a vertex not yet included
		
		for (int l=0; l<startVerticesSize; l++)
		    if (copyStart(l) == 0) {
			int vertexTag = startVertices(l);			
			vertexPtr = theGraph.getVertexPtr(vertexTag);			
			nextMark--;
			copyStart(l) = 1;
			vertexPtr->setTmp(currentMark);
			numFromStart++;
			(*theRefResult)(currentMark) = vertexPtr->getTag();
			l =startVerticesSize;
		    }
	    }
	}
	
	currentMark = numVertex-1; // set current to the first again
	nextMark =  numVertex - startVerticesSize -1;

	// we continue till the ID is full

	while (nextMark >= 0) {
	    // get the current vertex and its adjacency
	
	    vertexPtr = theGraph.getVertexPtr((*theRefResult)(currentMark));
	    const ID &adjacency = vertexPtr->getAdjacency();

	    // go through the vertices adjacency and add vertices which
	    // have not yet been Tmp'ed to the (*theRefResult)

	    int size = adjacency.Size();
	    for (int i=0; i<size; i++) {
	    
		int vertexTag = adjacency(i);
		vertexPtr = theGraph.getVertexPtr(vertexTag);
		if ((vertexPtr->getTmp()) == -1) {
		    vertexPtr->setTmp(nextMark);
		    avgProfile += currentMark - nextMark;

		    (*theRefResult)(nextMark--) = vertexTag;
		}
	    }
	    // go to the next vertex
	    //  we decrement because we are doing reverse Cuthill-McKee
	
	    currentMark--;

	    // check to see if graph is disconneted
	
	    if ((currentMark == nextMark) && (currentMark >= 0)) {
	    
		// loop over iter till we get a vertex not yet Tmped
		
		while (((vertexPtr = vertexIter2()) != 0) && 
		       (vertexPtr->getTmp() != -1)) 
		    ;
		
		nextMark--;
		vertexPtr->setTmp(currentMark);
		(*theRefResult)(currentMark) = vertexPtr->getTag();
	    }
	}
	
	if (j == 0 || minAvgProfile > avgProfile) {
	    minStartVertexTag = startVertices(j);
	    minAvgProfile = avgProfile;
	}

    }

    
    // now we numebr based on minStartVErtexTag

    // we first set the Tmp of all vertices to -1, indicating
    // they have not yet been added.
    
    Vertex *vertexPtr;
    VertexIter &vertexIter = theGraph.getVertices();
    
    while ((vertexPtr = vertexIter()) != 0)
	vertexPtr->setTmp(-1);

    // we now set up; setting our markers and set first vertices
    VertexIter &vertexIter2 = theGraph.getVertices();    
    int currentMark = numVertex-1;  // marks current vertex visiting.
    int nextMark = currentMark-1;
    
    vertexPtr = theGraph.getVertexPtr(minStartVertexTag);	
    (*theRefResult)(currentMark) = vertexPtr->getTag();
    vertexPtr->setTmp(currentMark);
    currentMark--;	
    
    int loc = startVertices.getLocation(minStartVertexTag);
    for (int k=0; k<startVerticesSize; k++)
	if (k != loc)
	    copyStart(k) = 0;
     

    int numFromStart = 1;
    while (numFromStart < startVerticesSize) {
	// get the current vertex and its adjacency

	vertexPtr = theGraph.getVertexPtr((*theRefResult)(currentMark));
	const ID &adjacency = vertexPtr->getAdjacency();

	// go through the vertices adjacency and add vertices which
	// have not yet been Tmp'ed to the (*theRefResult)

	int size = adjacency.Size();
	for (int i=0; i<size; i++) {
	    int vertexTag = adjacency(i);
	    int loc =startVertices.getLocation(vertexTag);
	    if (loc >= 0) {
		vertexPtr = theGraph.getVertexPtr(vertexTag);
		if ((vertexPtr->getTmp()) == -1) {
		    vertexPtr->setTmp(nextMark);
		    copyStart(loc) = 1;
		    numFromStart++;
		    (*theRefResult)(nextMark--) = vertexTag;
		}
	    }
	}

	// go to the next vertex
	//  we decrement because we are doing reverse Cuthill-McKee
	
	currentMark--;

	// check to see if graph is disconneted
	
	if (currentMark == nextMark && numFromStart < startVerticesSize) {
	    // loop over iter till we get a vertex not yet included
		
	    for (int l=0; l<startVerticesSize; l++)
		if (copyStart(l) == 0) {
		    int vertexTag = startVertices(l);			
		    vertexPtr = theGraph.getVertexPtr(vertexTag);			
		    nextMark--;
		    copyStart(l) = 1;
		    vertexPtr->setTmp(currentMark);
		    numFromStart++;
		    (*theRefResult)(currentMark) = vertexPtr->getTag();
		    l =startVerticesSize;
		}
	}	
    }
	
    currentMark = numVertex-1; // set current to the first again
    nextMark =  numVertex - startVerticesSize -1;


    currentMark = numVertex-1; // set current to the first again
    
    // we continue till the ID is full
    while (nextMark >= 0) {

	// get the current vertex and its adjacency
	
	vertexPtr = theGraph.getVertexPtr((*theRefResult)(currentMark));
	const ID &adjacency = vertexPtr->getAdjacency();
	
	// go through the vertices adjacency and add vertices which
	// have not yet been Tmp'ed to the (*theRefResult)
	
	int size = adjacency.Size();
	for (int i=0; i<size; i++) {
	    
	    int vertexTag = adjacency(i);
	    vertexPtr = theGraph.getVertexPtr(vertexTag);
	    if ((vertexPtr->getTmp()) == -1) {
		vertexPtr->setTmp(nextMark);
		(*theRefResult)(nextMark--) = vertexTag;
	    }
	}

	// go to the next vertex
	//  we decrement because we are doing reverse Cuthill-McKee
	
	currentMark--;
	
	// check to see if graph is disconneted
	
	if ((currentMark == nextMark) && (currentMark >= 0)) {
	    opserr << "WARNING:  MyRCM::number - Disconnected graph ";
	    
	    // loop over iter till we get a vertex not yet Tmped
	    
	    while (((vertexPtr = vertexIter2()) != 0) && 
		   (vertexPtr->getTmp() != -1)) 
		;
		
	    nextMark--;
	    vertexPtr->setTmp(currentMark);
	    (*theRefResult)(currentMark) = vertexPtr->getTag();
	}
	
    }

    // now set the vertex references instead of the vertex tags
    // in the result, we change the Tmp to indicate number and return
    
    for (int m=0; m<numVertex; m++) {
	int vertexTag = (*theRefResult)(m);
	vertexPtr = theGraph.getVertexPtr(vertexTag);
	vertexPtr->setTmp(m+1); // 1 through numVertex
	(*theRefResult)(m) = vertexPtr->getTag();
    }

    return *theRefResult;
}
Exemple #9
0
MStatus lassoTool::doRelease( MEvent & /*event*/ )
// Selects objects within the lasso
{
	MStatus							stat;
	MSelectionList					incomingList, boundingBoxList, newList;

	if (!firstDraw) {
		// Redraw the lasso to clear it.
		view.beginXorDrawing(true, true, 1.0f, M3dView::kStippleDashed);
		draw_lasso();
		view.endXorDrawing();
	}

	// We have a non-zero sized lasso.  Close the lasso, and sort
	// all the points on it.
	append_lasso(lasso[0].h, lasso[0].v);
	qsort( &(lasso[0]), num_points, sizeof( coord  ),
		(int (*)(const void *, const void *))xycompare);

	// Save the state of the current selections.  The "selectFromSceen"
	// below will alter the active list, and we have to be able to put
	// it back.
	MGlobal::getActiveSelectionList(incomingList);

	// As a first approximation to the lasso, select all components with
	// the bounding box that just contains the lasso.
	MGlobal::selectFromScreen( min.h, min.v, max.h, max.v,
							   MGlobal::kReplaceList );

	// Get the list of selected items from within the bounding box
	// and create a iterator for them.
	MGlobal::getActiveSelectionList(boundingBoxList);

	// Restore the active selection list to what it was before we
	// the "selectFromScreen"
	MGlobal::setActiveSelectionList(incomingList, MGlobal::kReplaceList);

	// Iterate over the objects within the bounding box, extract the
	// ones that are within the lasso, and add those to newList.
	MItSelectionList iter(boundingBoxList);
	newList.clear();

	bool	foundEntireObjects = false;
	bool	foundComponents = false;

	for ( ; !iter.isDone(); iter.next() ) {
		MDagPath	dagPath;
		MObject		component;
		MPoint		point;
		coord		pt;
		MObject     singleComponent;

		iter.getDagPath( dagPath, component );

		if (component.isNull()) {
			foundEntireObjects = true;
			continue; // not a component
		}

		foundComponents = true;

		switch (component.apiType()) {
		case MFn::kCurveCVComponent:
			{
				MItCurveCV curveCVIter( dagPath, component, &stat );
				for ( ; !curveCVIter.isDone(); curveCVIter.next() ) {
					point = curveCVIter.position(MSpace::kWorld, &stat );
					view.worldToView( point, pt.h, pt.v, &stat );
					if (!stat) {
						stat.perror("Could not get position");
						continue;
					}
					if ( point_in_lasso( pt ) ) {
						singleComponent = curveCVIter.cv();
						newList.add (dagPath, singleComponent);
					}
				}
				break;
			}

		case MFn::kSurfaceCVComponent:
			{
				MItSurfaceCV surfCVIter( dagPath, component, true, &stat );
				for ( ; !surfCVIter.isDone(); surfCVIter.next() ) {
					point = surfCVIter.position(MSpace::kWorld, &stat );
					view.worldToView( point, pt.h, pt.v, &stat );
					if (!stat) {
						stat.perror("Could not get position");
						continue;
					}
					if ( point_in_lasso( pt ) ) {
						singleComponent = surfCVIter.cv();
						newList.add (dagPath, singleComponent);
					}
				}
				break;
			}

		case MFn::kMeshVertComponent:
			{
				MItMeshVertex vertexIter( dagPath, component, &stat );
				for ( ; !vertexIter.isDone(); vertexIter.next() ) {
					point = vertexIter.position(MSpace::kWorld, &stat );
					view.worldToView( point, pt.h, pt.v, &stat );
					if (!stat) {
						stat.perror("Could not get position");
						continue;
					}
					if ( point_in_lasso( pt ) ) {
						singleComponent = vertexIter.vertex();
						newList.add (dagPath, singleComponent);
					}
				}
				break;
			}

		case MFn::kMeshEdgeComponent:
			{
				MItMeshEdge edgeIter( dagPath, component, &stat );
				for ( ; !edgeIter.isDone(); edgeIter.next() ) {
					point = edgeIter.center(MSpace::kWorld, &stat );
					view.worldToView( point, pt.h, pt.v, &stat );
					if (!stat) {
						stat.perror("Could not get position");
						continue;
					}
					if ( point_in_lasso( pt ) ) {
						singleComponent = edgeIter.edge();
						newList.add (dagPath, singleComponent);
					}
				}
				break;
			}

		case MFn::kMeshPolygonComponent:
			{
				MItMeshPolygon polygonIter( dagPath, component, &stat );
				for ( ; !polygonIter.isDone(); polygonIter.next() ) {
					point = polygonIter.center(MSpace::kWorld, &stat );
					view.worldToView( point, pt.h, pt.v, &stat );
					if (!stat) {
						stat.perror("Could not get position");
						continue;
					}
					if ( point_in_lasso( pt ) ) {
						singleComponent = polygonIter.polygon();
						newList.add (dagPath, singleComponent);
					}
				}
				break;
			}

		default:
#ifdef DEBUG
			cerr << "Selected unsupported type: (" << component.apiType()
				 << "): " << component.apiTypeStr() << endl;
#endif /* DEBUG */
			continue;
		}
	}

	// Warn user if zie is trying to select objects rather than components.
	if (foundEntireObjects && !foundComponents) {
		MGlobal::displayWarning("lassoTool can only select components, not entire objects.");
	}

	// Update the selection list as indicated by the modifier keys.
	MGlobal::selectCommand(newList, listAdjustment);

	// Free the memory that held our lasso points.
	free(lasso);
	lasso = (coord*) 0;
	maxSize = 0;
	num_points = 0;
 
	return MS::kSuccess;
}