Beispiel #1
0
void redraw(){

  int i;

  G_rgb(1,1,1);

  G_clear();

  for(i=0;i<numPolygons;i++){

    buildPoly(i);

  }

}
Beispiel #2
0
void redraw(){

 

  int i;

  G_rgb(1,1,1);

  G_clear();

  //printf("%d\n", numPolygons[thisObj]);

  for(i=0;i<numPolygons[thisObj];i++){

    buildPoly(i);

  }

}
Beispiel #3
0
void redraw(){
  
  
  int k = buildArray();
  
  int i, j;
  
  G_rgb(0,0,.3);
  
  G_clear();
  
  for(i =0; i < k; i++){
    buildPoly(i);
  }
  
  G_rgb(1,0,0);
  G_point((300/H)*lightPos[0]/lightPos[2] + 300, (300/H)*lightPos[1]/lightPos[2] + 300);
  /*
    
  //printf("%d\n", numPolygons[thisObj]);
  
  for(thisObj=0;thisObj<numObjects; thisObj++){
  
  for(i=0;i<numPolygons[thisObj];i++){
  
  buildPoly(i);
  
  
  }
  
  
  }
  */
  
  //  exit(1) ;
}
Beispiel #4
0
bool MOERTEL::Overlap::ClipelementsSH() {

  if (!havemxi_ || !havesxi_ || !havelines_ || !havesxim_ || !havelinem_){

			std::stringstream oss;
				oss << "***ERR*** MOERTEL::Overlap::Clipelements:\n"
					<< "***ERR*** initialization of Overlap class missing\n"
					<< "***ERR*** file/line: " << __FILE__ << "/" << __LINE__ << "\n";
			throw ReportError(oss);

  }
  
  const int nmnode = mseg_.Nnode();
  const int nsnode = sseg_.Nnode();
  bool ok = true;
  double eps = 1.0e-10; // GAH EPSILON


  // I am reading http://cs.fit.edu/~wds/classes/graphics/Clip/clip/clip.html and 
  // http://en.wikipedia.org/wiki/Sutherland–Hodgman_algorithm as I write this code.

  // I assume that the master segment is convex. It should be if this is a mesh. Secondly, the
  // slave segment is a square in its parametric space -1 <= \xi <= 1 and -1 <= \eta <= 1. It need
  // only be convex.

  // For the Sutherland-Hodgman algorithm, the slave segment is used for the clip polygon.

  // Start with an input list of polygon vertices, in the slave coordinate system. Note that these points
  // are ordered around the polygon, as i is the line number of the boundaries of the master seg.

  std::vector<double> s_poly_xi, s_poly_eta, t_poly_xi, t_poly_eta;

  // Put all the corners of the master segment into the polygon

  for (int i=0; i<nmnode; ++i) { // loop over the corners of the master seg

	s_poly_xi.push_back(mline_[i][0]); 
	s_poly_eta.push_back(mline_[i][1]);

  }

  // Clip that poly against the slave poly one edge at a time

  for (int clipedge = 0; clipedge < nsnode; ++clipedge) {

	// point on that clip edge (dim 2)
	double* PE = &sline_[clipedge][0];

	// the outward normal to the clip edge (dim 2)
	double* N = &sn_[clipedge][0];

	ok = buildPoly(s_poly_xi, s_poly_eta, t_poly_xi, t_poly_eta, PE, N);

	if(!ok){

		// there is no intersection between polys. However, it is possible that the
		// slave poly is completely contained within the master
		
		break;

	}

	// The target vectors now become the source vectors
	
	s_poly_xi = t_poly_xi;
	s_poly_eta = t_poly_eta;

  } // for (int clipedge=0; clipedge<3; ++clipedge)

  if(ok){ // We have a target polygon

		double xi[2];

		// Compress the polygon by removing adjacent points less than epsilon apart

		for(unsigned int p = t_poly_xi.size() - 1; p >= 1; p--){

			xi[0] = t_poly_xi[p] - t_poly_xi[p - 1];
			xi[1] = t_poly_eta[p] - t_poly_eta[p - 1];

			double dist = MOERTEL::length(xi, 2);

			if(dist <= eps){ // remove the point p

				t_poly_xi.erase(t_poly_xi.begin() + p);
				t_poly_eta.erase(t_poly_eta.begin() + p);

			}
		}

		// Check the last point too

		if(t_poly_xi.size() >= 2){
		
			xi[0] = t_poly_xi[t_poly_xi.size() - 1] - t_poly_xi[0];
			xi[1] = t_poly_eta[t_poly_xi.size() - 1] - t_poly_eta[0];

			double dist = MOERTEL::length(xi, 2);

			if(dist <= eps){ // remove the point p

				t_poly_xi.erase(t_poly_xi.end() - 1);
				t_poly_eta.erase(t_poly_eta.end() - 1);

			}
		}

		// Do we still have a polygon? If not, just move on

		if(t_poly_xi.size() < 3){

			return false;

		}

		// Store it in the polygon

		for (unsigned int p = 0; p < t_poly_xi.size(); ++p) {

			xi[0] = t_poly_xi[p];
			xi[1] = t_poly_eta[p];

			AddPointtoPolygon(p, xi);

		}

#if 0
		// make printout of the polygon so far
		{
		int np    = SizePointPolygon();
		std::vector<Teuchos::RCP<MOERTEL::Point> > point; PointView(point);

		std::cout << "Master is in slave" << std::endl;

		for (int p=0; p<np; ++p) {

			std::cout << "OVERLAP Clipelements: point " << std::setw(3) << point[p]->Id()
						<< " xi " << point[p]->Xi()[0]
						<< "/" << point[p]->Xi()[1] << std::endl;
		}
		point.clear();
		}
#endif
  
		return true;

  }

  //===========================================================================

  // We come down here if there is no polygon from the above. This could mean that the slave segment is
  // completely inside the master segment.
  
	std::vector<int> s_node_id;

	for (int i=0; i<nsnode; ++i) {

		bool ok = true;

		// get the slave point in master coords
		double* P = sxim_[i];

		// loop master clip edges
		for (int clipedge=0; clipedge<nmnode; ++clipedge) {

			// point on master clipedge
			double* PE = &mlinem_[clipedge][0];

			// the outward normal to the clip edge (dim 2)
			double* N = &mn_[clipedge][0];
        
			// clip point P against this edge
			// GAH - EPSILON clip test point
			ok = Clip_TestPoint(N,PE,P,1.0e-5);

			// put point in
			if (ok) 
				continue;
			else {
				ok = false;
				break;
			}
		} // for (int clipedge=0; clipedge<3; ++clipedge)

		// We will be here, with ok == true only if the point is inside ALL clip edges

		// don't put point in
		if (!ok)
			continue;
		else { // Point is inside ALL clip edges

			s_node_id.push_back(i);
		}
	} // for (int i=0; i<3; ++i)

	if(s_node_id.size() < static_cast<unsigned int>(nsnode)){ // Slave poly does not lie within master either. 
															// There is no overlap. Move on.

/* The reasoning here is that zero of the master polygon was found in the slave (no nodes). If the slave is completely
 * within the master, then all 4 nodes need to cleanly show up inside the master. If they do not, chances are only
 * a corner or edge of the master is touched.
 */

		return false;

	}

	// Slave is completely in master. Put the slave in the polygon
	
	for(unsigned int i = 0; i < s_node_id.size(); i++){

		//std::cout << "OVERLAP Clipelements: inserting slave point " << 1000+i << " xi="
		//     << sxi_[i][0] << "/" << sxi_[i][1] << endl;
		AddPointtoPolygon(i,sxi_[i]);

	}

#if 0
		// make printout of the polygon so far
		{
		int np    = SizePointPolygon();
		std::vector<Teuchos::RCP<MOERTEL::Point> > point; PointView(point);

		std::cout << "Slave is in master" << std::endl;

		for (int p=0; p<np; ++p) {

			std::cout << "OVERLAP Clipelements: point " << std::setw(3) << point[p]->Id()
						<< " xi " << point[p]->Xi()[0]
						<< "/" << point[p]->Xi()[1] << std::endl;
		}
		point.clear();
		}
#endif

	return true;
}