Exemplo n.º 1
0
void IntersectionProcessor::ProcessIntersection(
    const OpsDoublePoint &intersectionPt, WingedEdgeArray &edges)
{
    // loop through the edges generating an EdgeRecord for each of them

    m_nEdgeRecs = 0;

    for (int i = 0; i < edges.GetNEdges(); i++) {
        // if the intersection point is one of the edge endpoints, then
        // just add it

        if (intersectionPt == *edges[i]->m_vert[0])
            AddEdgeRecord(edges[i], 0);
        else if (intersectionPt == *edges[i]->m_vert[1])
            AddEdgeRecord(edges[i], 1);

        // else split the edge and add the two resulting edges

        else {
            WingedEdge *newEdge;
            SplitEdge(intersectionPt, edges[i], newEdge);
            AddEdgeRecord(edges[i], 0);
            AddEdgeRecord(newEdge, 1);
        }
    }

    // if more than two edge records, or the edges are coincident then sort
    // them into polar order before joining them about the intersection point

    if (m_nEdgeRecs > 2 || EdgesCoincident(edges[0], edges[1])) {
        SortEdges();
        JoinEdges(intersectionPt);
    }

    // else must have two non-coincident edges joined at a common endpoint -
    // handle this case directly since it occurs frequently

    else
        edges[0]->Join(edges[1], &intersectionPt);

#if defined _DEBUG
    if (traceFile != NULL)
        TraceIntersection(intersectionPt);
#endif

} // end: ProcessIntersection()
Exemplo n.º 2
0
int main(long argc, char** argv) {
  int i, j;
  long t;
  FILE* fp;

  double duration;
  clock_t time;
  struct timeval tpstart, tpend;
  long iTimeInterval;

  int Test = 0;

  if (argc != 4) {
    printf("usage: %s .max_graph_file num_threads GR frequency\n", argv[0]);
    exit(-1);
  }
  num_threads = atoi(argv[2]);
  fprintf(stderr, "Threads: \t\t%d\n", num_threads);

  // initialize the graph, will read the graph from a file.
  fp = fopen(argv[1], "r");
  if (!fp) {
    printf("Cannot open %s\n", argv[1]);
    exit(-1);
  }

  char tag;
  char str[5];
  int from, to, capacity;

  fscanf(fp, "%c", &tag);
  while (tag != 'p') {
    while (getc(fp) != '\n')
      ;
    fscanf(fp, "%c", &tag);
  }
  fscanf(fp, "%s %d %d", str, &g_num_nodes, &g_num_edges);

  gr_threshold = (int)(atof(argv[3]) * g_num_nodes);
  fprintf(stderr, "GR Freq: \t\t%2.2f\n", atof(argv[3]));
  fprintf(stderr, "%d nodes, %d edges\n\n", g_num_nodes, g_num_edges);

  // initialize graph
  init_graph();

  // read and sort edges
  Edge edge = (Edge)malloc(2 * g_num_edges * sizeof(struct edge_entry));
  if (edge == NULL)
    exit(-1);
  edge_sym = edge;
  edgecnt = 0;
  for (i = 0; i < g_num_edges;) {
    if (getc(fp) == 'a') {
      fscanf(fp, "%d	%d	%d/n", &from, &to, &capacity);
      edge = Addedge(from - 1, to - 1, capacity, 0, edge);
      i++;
    }
  }
  assert(i == g_num_edges);

  SortEdges();
  fprintf(stderr, "Edge sorted!\n");

  // initialize thread parameters
  init_threads(num_threads);
  pthread_t threads[num_threads];

  // initial barrier and lock
  pthread_mutex_init(&(gr_mutex), NULL);
  node_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t) * g_num_nodes);
  if (node_mutex == NULL)
    exit(-1);
  thread_mutex =
      (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t) * num_threads);
  if (thread_mutex == NULL)
    exit(-1);
  for (i = 0; i < num_threads; i++) {
    pthread_mutex_init(&(thread_mutex[i]), NULL);
  }
  for (i = 0; i < g_num_nodes; i++) {
    pthread_mutex_init(&(node_mutex[i]), NULL);
  }

  pthread_barrier_init(&start_barrier, NULL, num_threads);

  // now the f c e h arrays have been initialized. start the threads
  // so that they can work asynchronously.
  time = clock();
  gettimeofday(&tpstart, NULL);
  preflow(num_threads);
  for (t = 0; t < num_threads; t++) {
    pthread_create(&(threads[t]), NULL, scan_nodes, (void*)t);
  }
#ifdef MONITOR
  int num_idle_threads;
  int totalQsize, global_Q_size;
  while (!flow_done()){
    gettimeofday(&tpend, NULL);
    iTimeInterval = 1000000 * (tpend.tv_sec - tpstart.tv_sec);
    iTimeInterval += tpend.tv_usec - tpstart.tv_usec;
    duration = (double)iTimeInterval / 1000000;
    totalQsize = 0;
    num_idle_threads = 0;
    for (j = 0; j < num_threads; j++) {
      totalQsize += threadEnv[j].Qsize;
      if (threadEnv[j].Qsize == 0)
        num_idle_threads++;
    }
    if (duration > 10.0) {
                fprintf(stderr, " totalQsize: %8d globalQsize %4d idle %2d\n",
       totalQsize, global_Q_size, num_idle_threads);
              fflush(stderr);
                  exit(-1);
    }
    // printf("%12d %12d \t\t totalQsize: %8d GR %4d idel %2d\n",
    // g_node[0].excess,g_node[g_num_nodes-1].excess, totalQsize, GRcnt,
    // num_idle_threads);
    // printf("%d\n", totalQsize);
  }
  printf("\n");
#endif

  for (t = 0; t < num_threads; t++) {
    pthread_join(threads[t], NULL);
  }
  gettimeofday(&tpend, NULL);
  time = clock() - time;

  iTimeInterval = 1000000 * (tpend.tv_sec - tpstart.tv_sec);
  iTimeInterval += tpend.tv_usec - tpstart.tv_usec;
  duration = (double)iTimeInterval / 1000000;

  fprintf(stderr, "FLOW: \t\t\t%ld\n", sink->excess);
  fprintf(stderr, "Wall Time: \t\t%5.3f\n", duration);
  fprintf(stderr,
          "CPU Time: \t\t%5.3f\n",
          (double)time / CLOCKS_PER_SEC / num_threads);
  fprintf(stderr, "Push: \t\t\t%ld\n", totalPushes);
  fprintf(stderr, "Push Efcy: \t\t%.1f\n", totalPushes / duration);
  fprintf(stderr, "Lift: \t\t\t%ld\n", totalLifts);
  fprintf(stderr, "Lift Efcy: \t\t%.1f\n", totalLifts / duration);
  fprintf(stderr, "GR: \t\t\t%d\n", GRcnt);
  fprintf(stderr, "HELP: \t\t\t%d\n", HPcnt);
  fflush(stderr);

  check_violation();

  pthread_exit(NULL);
}
Exemplo n.º 3
0
std::list<SimplifySketchTool::SortPoint> SimplifySketchTool::GetPoints( TopoDS_Wire wire, const double deviation )
{
	std::list<SortPoint> points;

	std::vector<TopoDS_Edge> edges = SortEdges(wire);
	SortPoint last_position(0.0, 0.0, 0.0);

    for (std::vector<TopoDS_Edge>::size_type i=0; i<edges.size(); i++)
	{
		const TopoDS_Shape &E = edges[i];

		// enum GeomAbs_CurveType
		// 0 - GeomAbs_Line
		// 1 - GeomAbs_Circle
		// 2 - GeomAbs_Ellipse
		// 3 - GeomAbs_Hyperbola
		// 4 - GeomAbs_Parabola
		// 5 - GeomAbs_BezierCurve
		// 6 - GeomAbs_BSplineCurve
		// 7 - GeomAbs_OtherCurve

		BRepAdaptor_Curve curve(TopoDS::Edge(E));
		GeomAbs_CurveType curve_type = curve.GetType();

		switch(curve_type)
		{
			case GeomAbs_Line:
				// make a line
			{
				double uStart = curve.FirstParameter();
				double uEnd = curve.LastParameter();
				gp_Pnt PS;
				gp_Vec VS;
				curve.D1(uStart, PS, VS);
				gp_Pnt PE;
				gp_Vec VE;
				curve.D1(uEnd, PE, VE);

				if (last_position == SortPoint(PS))
				{
					// We're heading towards the PE point.
					SortPoint point(PE);
					points.push_back(point);
					last_position = point;
				} // End if - then
				else if (last_position == SortPoint(PE))
				{
					SortPoint point(PS);
					points.push_back(point);
					last_position = point;
				}
				else
				{
					SortPoint start(PS);
					SortPoint end(PE);

					if (i < (edges.size()-1))
					{
                        if (! DirectionTowarardsNextEdge( edges[i], edges[i+1] ))
                        {
                            // The next edge is closer to this edge's start point.  reverse direction
                            // so that the next movement is better.

                            SortPoint temp = start;
                            start = end;
                            end = temp;
                        }
					}

					points.push_back(start);
					points.push_back(end);
					last_position = end;
				}
			}
			break;


			default:
			{
				// make lots of small lines
				double uStart = curve.FirstParameter();
				double uEnd = curve.LastParameter();
				gp_Pnt PS;
				gp_Vec VS;
				curve.D1(uStart, PS, VS);
				gp_Pnt PE;
				gp_Vec VE;
				curve.D1(uEnd, PE, VE);

				TopoDS_Edge edge(TopoDS::Edge(E));
				BRepTools::Clean(edge);
				BRepMesh::Mesh(edge, deviation);

				TopLoc_Location L;
				Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(edge, L);
				if (!Polyg.IsNull()) {
					const TColgp_Array1OfPnt& Points = Polyg->Nodes();
					Standard_Integer po;
					int i = 0;
					std::list<SortPoint> interpolated_points;
					for (po = Points.Lower(); po <= Points.Upper(); po++, i++) {
						SortPoint p = (Points.Value(po)).Transformed(L);
						interpolated_points.push_back(p);
					} // End for

					// See if we should go from the start to the end or the end to the start.
					if (*interpolated_points.rbegin() == last_position)
					{
						// We need to go from the end to the start.  Reverse the point locations to
						// make this easier.

						interpolated_points.reverse();
					} // End if - then

					if (*interpolated_points.begin() != last_position)
					{
						// This curve is not nearby to the last_position.  Rapid to the start
						// point to start this off.

						// We need to move to the start BEFORE machining this line.
						SortPoint start(last_position);
						SortPoint end(*interpolated_points.begin());

						points.push_back(end);
						last_position = end;
					}

					for (std::list<SortPoint>::iterator itPoint = interpolated_points.begin(); itPoint != interpolated_points.end(); itPoint++)
					{
						if (*itPoint != last_position)
						{
							points.push_back(*itPoint);
							last_position = *itPoint;
						} // End if - then
					} // End for
				} // End if - then
			}
			break;
		} // End switch
	}

	return(points);
}