Example #1
0
int Nodes(BTNode *b)//求二叉树b的节点个数
{
	int num1, num2;
	if (b == NULL)
		return 0;
	else
		if (b->lchild == NULL&&b->rchild == NULL)
			return 1;
		else
		{
			num1 = Nodes(b->lchild);
			num2 = Nodes(b->rchild);
			return(num1 + num2 + 1);
		}
}
Example #2
0
// ------------------------------------------------------------------------------------------------
void Model::UpdateBounds()
{
    assert(m_constructed==true);
    const GeometryDict& geos = Geometries();
    if(geos.size()==0)
    {
        return;
    }

    float3 min = float3(FLT_MAX, FLT_MAX, FLT_MAX);
    float3 max = float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
    const NodeDict& nodes = Nodes();
    for(auto nodeIt = nodes.begin(); nodeIt != nodes.end(); ++nodeIt)
    {
        Node* node = nodeIt->second;
        for(auto geoIt = node->geometries.begin(); geoIt != node->geometries.end(); ++geoIt)
        {
            Geometry * geo = (*geoIt);
            AABB bbox = geo->mesh->bounds;
            bbox.Transform(m_nodeTransforms[node->index]);
            min = minimize(min, bbox.Min());
            max = maximize(max, bbox.Max());
        }
    }
    // note: min & max already transformed by entire object world matrix
    m_bounds = AABB(min, max);
}
Roadmap::Nodes Roadmap::gridNodes (const unsigned g) const
{
  if (gmu::contains(grid_nodes_, g))
    return gmu::keyValue(grid_nodes_, g);
  else
    return Nodes();  
}
Example #4
0
 vector<int> twoSum(vector<int> &numbers, int target) {
     // IMPORTANT: Please reset any member data you declared, as
     // the same Solution instance will be reused for each test case.
     int len = numbers.size();
     vector<int> result(2);
     if(len<2)
     return result;
     vector<Node> Nodes(len);
     for(int i=0;i<len;i++)
     {
         Nodes[i] = Node(numbers[i],i+1);
     }
     sort(Nodes.begin(),Nodes.end(),isLess);
     
     int i=0,j=len-1;
     while(i<j)
     {
         if(Nodes[i].val+Nodes[j].val==target)
         {
             result[0] = min(Nodes[i].indx,Nodes[j].indx);
             result[1] = max(Nodes[i].indx,Nodes[j].indx);
             break;
         }
         else if(Nodes[i].val+Nodes[j].val<target)
         i++;
         else
         j--;
     }
     return result;
 }
Example #5
0
void TypeHierarchy::addDown(const PTypeRef & t1,const PTypeRef & t2)
{
	GIC i = downGraph.find(&t1);
	GIC j = downGraph.find(&t2);
	if(i == downGraph.end())
	{
		i = graph.find(&t1);
		downGraph[i->first] = Nodes();
	};
	if(j == downGraph.end())
	{
		j = graph.find(&t2);
		downGraph[j->first] = Nodes();
		j = downGraph.find(&t2);
	};
	downGraph[&t1].insert(j->first);
};
Example #6
0
/*----------------------------------------------------------------------*
 | build an outward normal at a node adjacent to this        mwgee 10/05|
 | returns allocated vector of length 3 with outward normal             |
 *----------------------------------------------------------------------*/
double* MOERTEL::Segment_BiLinearTri::BuildNormal(double* xi)
{ 
  // linear triangles are planar, so we don't care were exactly to build the normal

  // build base vectors
  double g1[3];
  double g2[3];
  for (int i=0; i<3; ++i)
  {
    g1[i] = Nodes()[1]->X()[i] - Nodes()[0]->X()[i];  
    g2[i] = Nodes()[2]->X()[i] - Nodes()[0]->X()[i]; 
  }
  
  // build normal as their cross product
  double* n = new double[3];
  
  MOERTEL::cross(n,g1,g2);

  return n;
}
Example #7
0
static void ListCmdFn(cmdScannerADT cs)
{
    scannerADT scanner;
    symtabADT nodeTable;
    graphADT graph;
    nodeADT node, target;

    graph = GetCommandData(cs);
    foreach (node in Nodes(graph)) {
        printf("%s:", (string) GetNodeData(node));
        foreach (target in ConnectedNodes(node)) {
            printf(" %s", (string) GetNodeData(target));
        }
Example #8
0
void TGraphKey::TakeSig(const PNGraph& Graph, const int& MnSvdGraph, const int& MxSvdGraph) {
  const int Edges = Graph->GetEdges();
  Nodes = Graph->GetNodes();
  VariantId = 0;
  SigV.Gen(2+Nodes, 0);
  // degree sequence
  TIntPrV DegV(Nodes, 0);
  for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
    DegV.Add(TIntPr(NodeI.GetInDeg(), NodeI.GetOutDeg()));
  }
  DegV.Sort(false);
  SigV.Add(TFlt(Nodes));
  SigV.Add(TFlt(Edges));
  for (int i = 0; i < DegV.Len(); i++) {
    SigV.Add(DegV[i].Val1());
    SigV.Add(DegV[i].Val2());
  }
  // singular values signature
  //   it turns out that it is cheaper to do brute force isomorphism
  //   checking than to calculate SVD and then check isomorphism
  if (Nodes >= MnSvdGraph && Nodes < MxSvdGraph) {
    // perform full SVD
    TFltVV AdjMtx(Nodes+1, Nodes+1);
    TFltV SngValV;
    TFltVV LSingV, RSingV;
    TIntH NodeIdH;
    // create adjecency matrix
    for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
      NodeIdH.AddKey(NodeI.GetId());
    }
    for (TNGraph::TNodeI NodeI = Graph->BegNI(); NodeI < Graph->EndNI(); NodeI++) {
      const int NodeId = NodeIdH.GetKeyId(NodeI.GetId()) + 1;
      for (int e = 0; e < NodeI.GetOutDeg(); e++) {
        const int DstNId = NodeIdH.GetKeyId(NodeI.GetOutNId(e)) + 1;  // no self edges
        if (NodeId != DstNId) AdjMtx.At(NodeId, DstNId) = 1;
      }
    }
    try { // can fail to converge but results seem to be good
      TSvd::Svd(AdjMtx, LSingV, SngValV, RSingV);
    } catch(...) {
      printf("\n***No SVD convergence: G(%d, %d): SngValV.Len():%d\n", Nodes(), Graph->GetEdges(), SngValV.Len());
    }
    // round singular values
    SngValV.Sort(false);
    for (int i = 0; i < SngValV.Len(); i++) {
      SigV.Add(TMath::Round(SngValV[i], RoundTo));
    }
  }
  //printf("SIG:\n");  for (int i = 0; i < SigV.Len(); i++) { printf("\t%f\n", SigV[i]); }
  SigV.Pack();
}
void  
GEOM_ShadingFace:: 
OCC2VTK(const TopoDS_Face& theFace,  
        vtkPolyData* thePolyData, 
        vtkPoints* thePts) 
{
  TopLoc_Location aLoc;
  Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
  if(aPoly.IsNull()) 
    return;
  else{
    gp_Trsf myTransf;
    Standard_Boolean identity = true;
    if(!aLoc.IsIdentity()){
      identity = false;
      myTransf = aLoc.Transformation();
    }           
      
    Standard_Integer i; 
    int aNbOfNodes = thePts->GetNumberOfPoints();
    const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
    Standard_Integer nbNodesInFace = aPoly->NbNodes(); 
    for(i = 1; i <= nbNodesInFace; i++) {
      gp_Pnt P = Nodes(i);
      if(!identity) 
        P.Transform(myTransf);
      thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
    }

    const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
    Standard_Integer nbTriInFace = aPoly->NbTriangles();
    for(i = 1; i <= nbTriInFace; i++){
      // Get the triangle
      Standard_Integer N1,N2,N3;
      Triangles(i).Get(N1,N2,N3);
      N1 += aNbOfNodes - 1;
      N2 += aNbOfNodes - 1;
      N3 += aNbOfNodes - 1;
      vtkIdType anIds[3] = {N1, N2, N3};
      thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
    }
  } 
}
Example #10
0
Nodes NodeFactory::finishMakingElement(Element *element) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #11
0
Nodes NodeFactory::makeProcessingInstruction(void) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #12
0
Nodes NodeFactory::makeText(void) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #13
0
Nodes NodeFactory::makeAttribute(void) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #14
0
Nodes NodeFactory::makeDocType(xom::String rootElementName, xom::String publicID, xom::String systemID) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #15
0
std::vector<std::string> StrainMeasures::getSegmentStrains(std::string fieldName) {
	std::vector<std::string> strains(19);
	Cmiss_field_id field = Cmiss_field_module_find_field_by_name(field_module, fieldName.c_str());

	//Compute strains
	unsigned int numSegments = mySegments->size();
	double temp_array1[3];
	double temp_array2[3];
//#define printcoord
#ifdef printcoord
#include "MeshTopology.h"

	std::vector<Cmiss_node_id> myNodes(100);
	Cmiss_nodeset_id nodeset = Cmiss_field_module_find_nodeset_by_name(field_module, "cmiss_nodes");
	Cmiss_node_iterator_id nodeIterator = Cmiss_nodeset_create_node_iterator(nodeset);
	Cmiss_node_id node = Cmiss_node_iterator_next(nodeIterator);
	if (node != 0) {
		double temp_array[3];

		while (node) {
			int node_id = Cmiss_node_get_identifier(node);
			myNodes[node_id - 1] = node;
			node = Cmiss_node_iterator_next(nodeIterator);
		}
	}
	Cmiss_nodeset_destroy(&nodeset);
	Cmiss_node_iterator_destroy(&nodeIterator);

	std::vector<int> Nodes(27);

	Nodes[8] = aplaxNodes8;
	Nodes[7] = aplaxNodes7;
	Nodes[6] = aplaxNodes6;
	Nodes[5] = aplaxNodes5;
	Nodes[4] = aplaxNodes4;
	Nodes[3] = aplaxNodes3;
	Nodes[2] = aplaxNodes2;
	Nodes[1] = aplaxNodes1;
	Nodes[0] = aplaxNodes0;

	Nodes[9] = tchNodes0;
	Nodes[10] = tchNodes1;
	Nodes[11] = tchNodes2;
	Nodes[12] = tchNodes3;
	Nodes[13] = tchNodes4;
	Nodes[14] = tchNodes5;
	Nodes[15] = tchNodes6;
	Nodes[16] = tchNodes7;
	Nodes[17] = tchNodes8;

	Nodes[18] = fchNodes0;
	Nodes[19] = fchNodes1;
	Nodes[20] = fchNodes2;
	Nodes[21] = fchNodes3;
	Nodes[22] = fchNodes4;
	Nodes[23] = fchNodes5;
	Nodes[24] = fchNodes6;
	Nodes[25] = fchNodes7;
	Nodes[26] = fchNodes8;

#endif
	std::vector<std::vector<double> > aplaxLengths;
	std::vector<std::vector<double> > tchLengths;
	std::vector<std::vector<double> > fchLengths;
	double denomj = (numberOfModelFrames_ - 1.0);
	for (int i = 0; i < numberOfModelFrames_; i++) {
		std::vector<double> cLengths;
		double time = ((double) i) / denomj;
		Cmiss_field_cache_set_time(fieldCache, time);
#ifdef printcoord
		std::cout<<"Frame "<<i<<"\t"<<time<<"\t"<<mySegments->at(0).xia[2]<<std::endl;
#endif
		for (int j = 0; j < numSegments; j++) {
			WallSegment& seg = mySegments->at(j);
			//The the lengths
			temp_array1[0] = temp_array1[1] = temp_array1[2] = 0.0;
			temp_array2[0] = temp_array2[1] = temp_array2[2] = 0.0;
			//Since cmiss id starts at 1 subtract 1 from seg.elemeid?
			//Note that accessing some computed field (those that involve gradients), with multiple versions leads to gradient set to 0 warning
			Cmiss_field_cache_set_mesh_location(fieldCache, elements[seg.elementida - 1], 3, seg.xia);
			Cmiss_field_evaluate_real(field, fieldCache, 3, temp_array1);
			Cmiss_field_cache_set_mesh_location(fieldCache, elements[seg.elementidb - 1], 3, seg.xib);
			Cmiss_field_evaluate_real(field, fieldCache, 3, temp_array2);
			Point3D p1(temp_array1);
			Point3D p2(temp_array2);
			double dist = p1.distance(p2);
#ifdef printcoord
			{
				int nodeCtr = (j / 8) * 9 + j % 8;
				Cmiss_field_cache_set_node(fieldCache, myNodes[Nodes[nodeCtr]]);
				temp_array1[0] = temp_array1[1] = temp_array1[2] = 0.0;
				Cmiss_field_evaluate_real(field, fieldCache, 3, temp_array1);
				Point3D p3(temp_array1);
				Cmiss_field_cache_set_node(fieldCache, myNodes[Nodes[nodeCtr + 1]]);
				temp_array1[0] = temp_array1[1] = temp_array1[2] = 0.0;
				Cmiss_field_evaluate_real(field, fieldCache, 3, temp_array1);
				Point3D p4(temp_array1);
				std::cout << p1 << "\t" << p2 << " = " << dist << "\t:\t Value at " << Nodes[nodeCtr] + 1 << "\t" << p3 << "\t" << p1.distance(p3) << "\t" << Nodes[nodeCtr + 1] + 1
						<< "\t" << p4 << "\t" << p2.distance(p4) << "\t distance \t " << p3.distance(p4) << std::endl;
			}
#endif
			cLengths.push_back(dist);
		}

		for (int segc = 0; segc < numSegments / 8; segc++) {
			int offset = segc * 8;
			std::vector<double> sLengths;

			sLengths.push_back(cLengths[0 + offset] + (1 / 3.0 - 1 / 4.0) * 4 * cLengths[1 + offset]);
			sLengths.push_back((1.0 - (1 / 3.0 - 1 / 4.0)) * 4 * cLengths[1 + offset] + (2 / 3.0 - 1 / 2.0) * 4 * cLengths[2 + offset]);
			sLengths.push_back((1.0 - (2 / 3.0 - 1 / 2.0)) * 4 * cLengths[2 + offset] + cLengths[3 + offset]);
			sLengths.push_back(cLengths[4 + offset] + (1.0 - (2 / 3.0 - 1 / 2.0)) * 4 * cLengths[5 + offset]);
			sLengths.push_back((2 / 3.0 - 1 / 2.0) * 4 * cLengths[5 + offset] + (1.0 - (1 / 3.0 - 1 / 4.0)) * 4 * cLengths[6 + offset]);
			sLengths.push_back((1 / 3.0 - 1 / 4.0) * 4 * cLengths[6 + offset] + cLengths[7 + offset]);

			if (segc == 0)
				aplaxLengths.push_back(sLengths);
			else if (segc == 1)
				tchLengths.push_back(sLengths);
			else
				fchLengths.push_back(sLengths);
		}
	}
	std::vector<double> avgStrains(numberOfModelFrames_, 0.0);

	for (int segc = 0; segc < numSegments / 8; segc++) {
		std::vector<std::vector<double> > dstrains;
		std::vector<std::vector<double> > distances;
		if (segc == 0)
			distances = aplaxLengths;
		else if (segc == 1)
			distances = tchLengths;
		else if (segc == 2)
			distances = fchLengths;

		std::vector<double>& initStrain = distances[0];
		for (int frame = 1; frame < numberOfModelFrames_; frame++) { //Compute Strains
			std::vector<double>& curStrainLengths = distances[frame];
			std::vector<double> curStrain;
			double c = 0;
			unsigned int ulimit = initStrain.size();
			for (int j = 0; j < ulimit; j++) {
				c = 100.0 * (curStrainLengths[j] - initStrain[j]) / initStrain[j];
				curStrain.push_back(c);
			}
			dstrains.push_back(curStrain);
		}

		std::vector<std::string> strainSeries;

		for (int j = 0; j < initStrain.size(); j++) {
			std::ostringstream ss;
			ss << 0.0; //For init step

			int denom = numberOfModelFrames_ - 1;
			double maxStrain = dstrains[denom - 1][j];
			//Note that frame goes from 1 to heart.numberOfModelFrames_ when computing strain
			//so shift down by 1
			for (int i = 0; i < denom; i++) { //Compute Strains
											  //Drift compensate
				double stc = dstrains[i][j] - (i + 1) * maxStrain / denom;
				ss << "," << stc;
				avgStrains[i] += stc;
			}
			strainSeries.push_back(ss.str());
		}
		if (segc == 0) {
			strains[2 - 1] = strainSeries[5];
			strains[8 - 1] = strainSeries[4];
			strains[17 - 1] = strainSeries[3];
			strains[18 - 1] = strainSeries[2];
			strains[11 - 1] = strainSeries[1];
			strains[5 - 1] = strainSeries[0];
		} else if (segc == 2) {
			strains[3 - 1] = strainSeries[0];
			strains[9 - 1] = strainSeries[1];
			strains[14 - 1] = strainSeries[2];
			strains[16 - 1] = strainSeries[3];
			strains[12 - 1] = strainSeries[4];
			strains[6 - 1] = strainSeries[5];
		} else if (segc == 1) {
			strains[4 - 1] = strainSeries[0];
			strains[10 - 1] = strainSeries[1];
			strains[15 - 1] = strainSeries[2];
			strains[13 - 1] = strainSeries[3];
			strains[7 - 1] = strainSeries[4];
			strains[1 - 1] = strainSeries[5];
		}
	}
#ifdef printcoord
	std::cout << "Linear 3D " << fieldName << std::endl;
	for (int i = 1; i < 100; i++)
		Cmiss_node_destroy(&myNodes[i]);

#endif
	//Add the average strain
	//Num strain segments depends on the number of active segments (6 strain segments per view, which has 8 active segments)
	double denom = (numSegments / 8) * 6;

	std::ostringstream ss;
	ss << 0.0; //For init step
	for (int i = 0; i < numberOfModelFrames_ - 1; i++) { //Compute the Average
		ss << "," << avgStrains[i] / denom;
	}
	strains[18] = ss.str();

	//Check if model PGS should be calculated
	if (computeModelPGS) {
		double max = fabs(avgStrains[0]);
		int idx = 0;
		for (int i = 1; i < numberOfModelFrames_ - 1; i++) {
			if (fabs(avgStrains[i]) > max) {
				max = fabs(avgStrains[i]);
				idx = i;
			}
		}
		modelPGS = avgStrains[idx] / denom;
		computeModelPGS = false; //set it so that it is not computed in subsequent calls
	}

	Cmiss_field_destroy(&field);

	return strains;
}
Example #16
0
/**
 * Not currently supported.
 */
Nodes XSLTransform::transform(Nodes in) throw(XSLException) {
	ASSERTP(false, "unsupported");
	return Nodes();
}
Example #17
0
void DrawFace(TopoDS_Face face,void(*callbackfunc)(const double* x, const double* n), bool just_one_average_normal)
{
	double x[9], n[9];

	StdPrs_ToolShadedShape SST;

	// Get triangulation
	TopLoc_Location L;
	Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(face,L);
	gp_Trsf tr = L;

	if(facing.IsNull()){
#if 0
		BRepAdaptor_Surface surface(face, Standard_True);
		double u0 = surface.FirstUParameter();
		double u1 = surface.LastUParameter();
		double v0 = surface.FirstVParameter();
		double v1 = surface.LastVParameter();

		const int numi = 10;
		const int numj = 10;

		for(int i = 0; i<numi; i++)
		{
			for(int j = 0; j<numj; j++)
			{
				double uA = -1.2 + 2.5 *(double)i / numi;
				double uB = -1.2 + 2.5 *(double)(i+1) / numi;
				double vA = 10* (double)j / numj;
				double vB = 10*(double)(j+1) / numj;
				gp_Pnt p0, p1, p2, p3;
				gp_Dir n0 = GetFaceNormalAtUV(face, uA, vA, &p0);
				gp_Dir n1 = GetFaceNormalAtUV(face, uB, vA, &p1);
				gp_Dir n2 = GetFaceNormalAtUV(face, uB, vB, &p2);
				gp_Dir n3 = GetFaceNormalAtUV(face, uA, vB, &p3);

				x[0] = p0.X();
				x[1] = p0.Y();
				x[2] = p0.Z();
				x[3] = p1.X();
				x[4] = p1.Y();
				x[5] = p1.Z();
				x[6] = p2.X();
				x[7] = p2.Y();
				x[8] = p2.Z();

				n[0] = n0.X();
				n[1] = n0.Y();
				n[2] = n0.Z();
				n[3] = n1.X();
				n[4] = n1.Y();
				n[5] = n1.Z();
				n[6] = n2.X();
				n[7] = n2.Y();
				n[8] = n2.Z();

				(*callbackfunc)(x, n);

				x[0] = p0.X();
				x[1] = p0.Y();
				x[2] = p0.Z();
				x[3] = p2.X();
				x[4] = p2.Y();
				x[5] = p2.Z();
				x[6] = p3.X();
				x[7] = p3.Y();
				x[8] = p3.Z();

				n[0] = n0.X();
				n[1] = n0.Y();
				n[2] = n0.Z();
				n[3] = n2.X();
				n[4] = n2.Y();
				n[5] = n2.Z();
				n[6] = n3.X();
				n[7] = n3.Y();
				n[8] = n3.Z();

				(*callbackfunc)(x, n);
			}
		}
#endif
	}
	else
	{
		Poly_Connect pc(facing);	
		const TColgp_Array1OfPnt& Nodes = facing->Nodes();
		const Poly_Array1OfTriangle& triangles = facing->Triangles();
		TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper());

		SST.Normal(face, pc, myNormal);

		Standard_Integer nnn = facing->NbTriangles();					// nnn : nombre de triangles
		Standard_Integer nt, n1, n2, n3 = 0;						// nt  : triangle courant
		// ni  : sommet i du triangle courant
		for (nt = 1; nt <= nnn; nt++)					
		{
			if (SST.Orientation(face) == TopAbs_REVERSED)			// si la face est "reversed"
				triangles(nt).Get(n1,n3,n2);						// le triangle est n1,n3,n2
			else 
				triangles(nt).Get(n1,n2,n3);						// le triangle est n1,n2,n3

			if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) )
			{
				gp_Pnt v1 = Nodes(n1).Transformed(tr);
				gp_Pnt v2 = Nodes(n2).Transformed(tr);
				gp_Pnt v3 = Nodes(n3).Transformed(tr);

				x[0] = v1.X();
				x[1] = v1.Y();
				x[2] = v1.Z();
				x[3] = v2.X();
				x[4] = v2.Y();
				x[5] = v2.Z();
				x[6] = v3.X();
				x[7] = v3.Y();
				x[8] = v3.Z();

				if(just_one_average_normal)
				{
					gp_Vec V1(v1, v2);
					gp_Vec V2(v1, v3);
					extract((V1 ^ V2).Normalized(), n);
				}
				else
				{
					n[0] = myNormal(n1).X();
					n[1] = myNormal(n1).Y();
					n[2] = myNormal(n1).Z();
					n[3] = myNormal(n2).X();
					n[4] = myNormal(n2).Y();
					n[5] = myNormal(n2).Z();
					n[6] = myNormal(n3).X();
					n[7] = myNormal(n3).Y();
					n[8] = myNormal(n3).Z();
				}

				(*callbackfunc)(x, n);
			}
		}
	}
}
Example #18
0
    SALOME_WNT_EXPORT
    int Export( const TopoDS_Shape& theShape,
                const TCollection_AsciiString& theFileName,
                const TCollection_AsciiString& theFormatName)
    {
        MESSAGE("Export OBJ into file " << theFileName.ToCString());

        std::ofstream fout(theFileName.ToCString());

        Standard_Real Umin, Umax, Vmin, Vmax, dUmax, dVmax;
        TopExp_Explorer ExpFace;
        StdPrs_ToolShadedShape SST;

        //Triangulate
        BRepMesh::Mesh(theShape, DEFAULT_DEVIATION);

        Standard_Integer ShapeId = 1;

        Standard_Integer baseV = 0;
        Standard_Integer baseN = 0;
        Standard_Integer baseT = 0;

        for(ExpFace.Init(theShape, TopAbs_FACE); ExpFace.More(); ExpFace.Next()) {

            TopoDS_Face myFace = TopoDS::Face(ExpFace.Current());
            TopLoc_Location aLocation;

            Handle(Poly_Triangulation) myT = BRep_Tool::Triangulation(myFace, aLocation);

            if (!myT.IsNull()) {

                Poly_Connect pc(myT);

                //write vertex buffer
                const TColgp_Array1OfPnt& Nodes = myT->Nodes();
                for (int i = Nodes.Lower(); i <= Nodes.Upper(); i++) {
                    gp_Pnt p = Nodes(i).Transformed(aLocation.Transformation());
                    fout << "v " << p.X() << " " << p.Y() << " " << p.Z() << std::endl;
                }
                fout << std::endl;

                //write normal buffer
                TColgp_Array1OfDir myNormal(Nodes.Lower(), Nodes.Upper());
                SST.Normal(myFace, pc, myNormal);
                //myNormal.Length();
                for (int i = myNormal.Lower(); i <= myNormal.Upper(); i++) {
                    gp_Dir d = myNormal(i).Transformed(aLocation.Transformation());
                    fout << "vn " << d.X() << " " << d.Y() << " " << d.Z() << std::endl;
                }
                fout << std::endl;

                //write uvcoord buffer
                BRepTools::UVBounds(myFace,Umin, Umax, Vmin, Vmax);
                dUmax = (Umax - Umin);
                dVmax = (Vmax - Vmin);
                const TColgp_Array1OfPnt2d& UVNodes = myT->UVNodes();
                for (int i = UVNodes.Lower(); i <= UVNodes.Upper(); i++) {
                    gp_Pnt2d d = UVNodes(i);

                    Standard_Real u = (-UOrigin+(URepeat*(d.X()-Umin))/dUmax)/ScaleU;
                    Standard_Real v = (-VOrigin+(VRepeat*(d.Y()-Vmin))/dVmax)/ScaleV;

                    fout << "vt " << u << " " << v << " 0" << std::endl;
                }
                fout << std::endl;

                //write triangle buffer
                if (Interface_Static::IVal("write.obj.groups"))
                    fout << "g face_" << ShapeId++ << std::endl;

                Standard_Integer n1 , n2 , n3;
                const Poly_Array1OfTriangle& triangles = myT->Triangles();

                for (int nt = 1; nt <= myT->NbTriangles(); nt++) {
                    if (SST.Orientation(myFace) == TopAbs_REVERSED)
                        triangles(nt).Get(n1,n3,n2);
                    else
                        triangles(nt).Get(n1,n2,n3);
                    if (TriangleIsValid (Nodes(n1),Nodes(n2),Nodes(n3)) ) {

                        fout << "f " <<n1 + baseV<<"/"<<n1 + baseT<<"/"<<n1 + baseN<<" "
                             <<n2 + baseV<<"/"<<n2 + baseT<<"/"<<n2 + baseN<<" "
                             <<n3 + baseV<<"/"<<n3 + baseT<<"/"<<n3 + baseN<<" "
                             <<std::endl;
                    }
                }
                fout << std::endl;

                baseV += Nodes.Length();
                baseN += myNormal.Length();
                baseT += UVNodes.Length();
            }
        }

        fout << std::flush;
        fout.close();

        return 1;
    }
void * 
OPS_ZeroLengthInterface2D(void) {

  if (numZeroLengthInterface2D == 0) {
    numZeroLengthInterface2D++;
    opserr << "ZeroLengthContactNTS2d - Written by Roozbeh G. Mikola and N.Sitar, UC Berkeley\n";
  }

  Element *theEle = 0;
  int numData = 0;  

  // get the ele tag
  int eleTag, sNdNum, mNdNum, sDOF, mDOF;
  numData = 1;

  if (OPS_GetInt(&numData, &eleTag) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalid eleTag \n";
    return 0;
  }

  const char *nextString = OPS_GetString();

  if (strcmp(nextString,"-sNdNum") != 0) {
    opserr << "ZeroLengthInterface2D:: expecting -sNdNum \n";
    return 0;
  }

  // get the number of slave nodes
  numData = 1;
  if (OPS_GetInt(&numData, &sNdNum) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalied sNdNum \n";
    return 0;
  }

  numData = 10;
  nextString = OPS_GetString();

  if (strcmp(nextString,"-mNdNum") != 0) {
    opserr << "ZeroLengthInterface2D:: expecting -mNdNum\n";
    return 0;
  }
  
  numData = 1;
  if (OPS_GetInt(&numData, &mNdNum) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalied sNdNum \n";
    return 0;
  }

  numData = 10;
  nextString = OPS_GetString();

  if (strcmp(nextString,"-dof") != 0) {
    opserr << "ZeroLengthInterface2D:: expecting -sdof in "<<
      "element zeroLengthInterface2D eleTag? -sNdNum sNdNum? -mNdNum mNdNum? -dof sdof? mdof? -Nodes Nodes? Kn? Kt? phi? \n" ;
    return 0;
  }

  numData = 1;
  if (OPS_GetInt(&numData, &sDOF) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalied sDOF\n";
    return 0;
  }

  numData = 1;
  if (OPS_GetInt(&numData, &mDOF) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalied mDOF\n";
    return 0;
  }

  // a quick check on number of args
  int argc = OPS_GetNumRemainingInputArgs();
  if (argc < 3 + sNdNum + mNdNum) {
    opserr << "ZeroLengthInterface2D::WARNING too few arguments " <<
      "element zeroLengthInterface2D eleTag? -sNdNum sNdNum? -mNdNum mNdNum? -dof sdof? mdof? -Nodes Nodes? Kn? Kt? phi? \n" ;
    return 0;
  }

  numData = 10;
  nextString = OPS_GetString();

  if (strcmp(nextString,"-Nodes") != 0) {
    opserr << "ZeroLengthInterface2D:: expecting -Nodes\n";
    return 0;
  }

  // read the Nodes values
  numData = sNdNum+mNdNum;
  int *theNodeData = new int[numData];
  ID  Nodes(theNodeData, numData);

  if (OPS_GetInt(&numData, theNodeData) != 0) {
    opserr << "ZeroLengthInterface2D:: not enough node tags provided for ele: ";
    opserr << eleTag << "\n";
    return 0;
  }

  // read the material properties
  numData = 3;
  double dData[3];
  if (OPS_GetDouble(&numData, dData) != 0) {
    opserr << "ZeroLengthInterface2D::WARNING invalid Kn,Kt or phi\n" ;
    return 0;
  }

  //
  // now we create the element and add it to the domain
  //
  
  theEle = new ZeroLengthInterface2D(eleTag, sNdNum, mNdNum, sDOF, mDOF, Nodes, dData[0], dData[1], dData[2]);
  return theEle;
}
Example #20
0
void CEdge::glCommands(bool select, bool marked, bool no_color){
	if(!no_color){
		wxGetApp().glColorEnsuringContrast(HeeksColor(0, 0, 0));
	}

	if(m_owner && m_owner->m_owner && m_owner->m_owner->GetType() == SolidType)
	{
		// triangulate a face on the edge first
		if(this->m_faces.size() > 0)
		{
			TopLoc_Location fL;
			Handle_Poly_Triangulation facing = BRep_Tool::Triangulation(m_faces.front()->Face(),fL);

			if(!facing.IsNull())
			{
				// Get polygon
				Handle_Poly_PolygonOnTriangulation polygon = BRep_Tool::PolygonOnTriangulation(m_topods_edge, facing, fL);
				gp_Trsf tr = fL;
				double m[16];
				extract_transposed(tr, m);
				glPushMatrix();
				glMultMatrixd(m);

				if (!polygon.IsNull())
				{
					glBegin(GL_LINE_STRIP);
					const TColStd_Array1OfInteger& Nodes = polygon->Nodes();
					const TColgp_Array1OfPnt& FNodes = facing->Nodes();
					int nnn = polygon->NbNodes();
					for (int nn = 1; nn <= nnn; nn++)
					{
						gp_Pnt v = FNodes(Nodes(nn));
						glVertex3d(v.X(), v.Y(), v.Z());
					}
					glEnd();
				}

				glPopMatrix();
			}
		}
	}
	else
	{
		bool glwidth_done = false;
		GLfloat save_depth_range[2];
		if(m_owner == NULL || m_owner->m_owner == NULL || m_owner->m_owner->GetType() != WireType)
		{
			BRepTools::Clean(m_topods_edge);
			double pixels_per_mm = wxGetApp().GetPixelScale();
			BRepMesh_IncrementalMesh(m_topods_edge, 1/pixels_per_mm);
			if(marked){
				glGetFloatv(GL_DEPTH_RANGE, save_depth_range);
				glDepthRange(0, 0);
				glLineWidth(2);
				glwidth_done = true;
			}
		}

		TopLoc_Location L;
		Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(m_topods_edge, L);
		if (!Polyg.IsNull()) {
			const TColgp_Array1OfPnt& Points = Polyg->Nodes();
			Standard_Integer po;
			glBegin(GL_LINE_STRIP);
			for (po = Points.Lower(); po <= Points.Upper(); po++) {
				gp_Pnt p = (Points.Value(po)).Transformed(L);
				glVertex3d(p.X(), p.Y(), p.Z());
			}
			glEnd();
		}

		if(glwidth_done)
		{
			glLineWidth(1);
			glDepthRange(save_depth_range[0], save_depth_range[1]);
		}
	}
}
int FunctionXFEM_EXAMPLE_CRACK1::solveTimeStep(const NumLib::TimeStep &/*time*/)
{
    INFO("-> solve %s", this->getProcessName().c_str());
    const size_t NodeNum = _msh->getNumberOfNodes();
    const size_t ElemNum = _msh->getNumberOfElements();

    // define test case parameters
    const double k1 = 1.0;
    const double EE = 10000.;
    const double nu = 0.3;
    const double fx = 0, fy = 0;
    const double mu = EE/(2.*(1.+nu));
    //lambda = EE*nu/((1+nu)*(1-2*nu)); % plane strain
    //kappa = 3-4*nu; % plane strain
    const double lambda = EE*nu/(1.-nu*nu); // plane stress
    const double kappa  = (3.-nu)/(1.+nu); // plane stress

    // get level-set function
    std::vector<double> ff(NodeNum);
    for (size_t i=0; i<NodeNum; i++)
        ff[i] = _msh->getNodeCoordinatesRef(i)->getData()[1];

    // Get exact solution at the nodes.
    std::vector<double> uuExact(NodeNum, .0), vvExact(NodeNum, .0);
    for (size_t i=0; i<NodeNum; i++) {
        const GeoLib::Point *pt = _msh->getNodeCoordinatesRef(i);
        exactSol_Mode1((*pt)[0], (*pt)[1], k1, kappa, mu, lambda, uuExact[i], vvExact[i]);
        _exact_displacement->getValue(i)(0) = uuExact[i];
        _exact_displacement->getValue(i)(1) = vvExact[i];
    }

    // define Dirichlet BC
    std::vector<size_t> Bound;
    searchMinMaxNodes(*_msh, Bound);
    std::vector<size_t> uDirNodes(Bound), vDirNodes(Bound);
    for (size_t i=0; i<vDirNodes.size(); i++)
        vDirNodes[i] += NodeNum;
    std::vector<double> uDirValues(Bound.size()), vDirValues(Bound.size());
    for (size_t i=0; i<Bound.size(); i++) {
        uDirValues[i] = uuExact[Bound[i]];
        vDirValues[i] = vvExact[Bound[i]];
    }

    // Get enriched elements and nodes.
    std::vector<size_t> ElemsEnriched, NodesEnriched;
    getEnrichedNodesElems(*_msh, ff, ElemsEnriched, NodesEnriched);
    std::set<size_t> SetNodesEnriched;
    SetNodesEnriched.insert(NodesEnriched.begin(), NodesEnriched.end());

    // initialize LinearEQS
    MathLib::EigenDenseLinearEquation leqs;
    leqs.create(4*NodeNum);
    INFO("* Nr. of DoFs = %d", 4*NodeNum);

    // domain integration
    INFO("* start Domain integration");
    for (size_t i=0; i<ElemNum; i++) {

        MeshLib::IElement* e = _msh->getElement(i);
        const size_t n_ele_nodes = e->getNumberOfNodes();
        Eigen::VectorXi Nodes(n_ele_nodes);
        FemLib::IFiniteElement* fe = _feObjects->getFeObject(*e);
        MathLib::LocalVector xxElem(n_ele_nodes), yyElem(n_ele_nodes);
        MathLib::LocalVector ffEle(n_ele_nodes);
        for (size_t j=0; j<n_ele_nodes; j++) {
            Nodes(j) = e->getNodeID(j);
            xxElem(j) = _msh->getNodeCoordinatesRef(e->getNodeID(j))->getData()[0];
            yyElem(j) = _msh->getNodeCoordinatesRef(e->getNodeID(j))->getData()[1];
            ffEle(j) = ff[e->getNodeID(j)];
        }

        // activate nodes are enriched
        MathLib::LocalVector NodesAct(n_ele_nodes);
        for (size_t i=0; i<n_ele_nodes; i++) {
            NodesAct(i) = (SetNodesEnriched.count(Nodes(i))>0 ? 1 : 0);
        }

        // set integration points in the reference element
        FemLib::IFemNumericalIntegration *q = fe->getIntegrationMethod();
        const size_t nQnQ = q->getNumberOfSamplingPoints();
        std::vector<GeoLib::Point> vec_int_ref_xx(nQnQ);
        std::vector<double> vec_int_ref_w(nQnQ);
        for (size_t j=0; j<nQnQ; j++) {
            q->getSamplingPoint(j, vec_int_ref_xx[j].getData());
            vec_int_ref_w[j] = q->getWeight(j);
        }
        MathLib::LocalVector xxIntRef, yyIntRef, wwIntRef;
        IntPoints2DLevelSet(
                ffEle, vec_int_ref_xx, vec_int_ref_w, nQnQ,
                xxIntRef, yyIntRef, wwIntRef);
        const size_t Curr_nQ = xxIntRef.rows();

        // get shape functions
        MathLib::LocalMatrix N, dNdx, dNdy;
        MathLib::LocalMatrix M, dMdx, dMdy;
        MathLib::LocalVector xxInt, yyInt, wwInt;
        MathLib::LocalVector ffInt;
        ShapeFctsXFEMSign(
                xxElem, yyElem, ffEle, NodesAct, xxIntRef, yyIntRef, wwIntRef,
                Curr_nQ,
                N, dNdx, dNdy, M, dMdx, dMdy, xxInt, yyInt, wwInt, ffInt);

        // integrate
        BuildMatRhs_Hooke(
                N, dNdx, dNdy, M, dMdx, dMdy,
                xxInt, yyInt, wwInt, ffInt, Nodes,
                lambda, lambda, mu, mu, fx, fy, Curr_nQ, NodeNum,
                leqs);
    }

    // Insert Dirichlet BCs.
    INFO("* insert Dirichlet BCs.");
    leqs.setKnownX(uDirNodes, uDirValues);
    leqs.setKnownX(vDirNodes, vDirValues);
    std::vector<size_t> uNonEnrichedNodes, vNonEnrichedNodes;
    for (size_t i=0; i<NodeNum; i++) {
        if (SetNodesEnriched.count(i) ==0) {
            uNonEnrichedNodes.push_back(i+NodeNum*2);
            vNonEnrichedNodes.push_back(i+NodeNum*3);
        }
    }
    std::vector<double> zeroEnrichedValue(uNonEnrichedNodes.size(), .0);
    leqs.setKnownX(uNonEnrichedNodes, zeroEnrichedValue);
    leqs.setKnownX(vNonEnrichedNodes, zeroEnrichedValue);

    // Solve system of equations for solution.
    INFO("* solve system of equations");
    leqs.solve();

    double *x = leqs.getX();
    for (size_t i=0; i<_displacement->getNumberOfNodes(); i++) {
        _displacement->getValue(i)(0) = x[i];
        _displacement->getValue(i)(1) = x[i+NodeNum];
    }

    return 0;
}