Пример #1
0
std::vector<double> stetmesh::Tet::getRanPnt(srng::RNG * r, uint n) const
{
	double * p = new double[n*3];

	double * p0 = _getVertex(0);
	double * p1 = _getVertex(1);
	double * p2 = _getVertex(2);
	double * p3 = _getVertex(3);
	/*double p0[3] = {pnt0[0], pnt0[1], pnt0[2]}; 	// Defunct code
	double p1[3] = {pnt1[0], pnt1[2], pnt1[2]};
	double p2[3] = {pnt2[0], pnt2[1], pnt2[2]};
	double p3[3] = {pnt3[0], pnt3[1], pnt3[2]}; */
	for (uint i=0; i< n; ++i)
	{
		double rn1 = r->getUnfIE();
		double rn2 = r->getUnfIE();
		double rn3 = r->getUnfIE();
		steps::math::tet_ranpnt(p0, p1, p2, p3, rn1, rn2, rn3, (p+(i*3)));
	}

	std::vector<double> pnt(n*3);
	for (uint i=0; i< (n*3); ++i)
	{
		pnt[i] = p[i];
	}
	delete[] p;

	return pnt;
}
Пример #2
0
bool stetmesh::Tet::isInside(std::vector<double> p) const
{
	double * p0 = _getVertex(0);
	double * p1 = _getVertex(1);
	double * p2 = _getVertex(2);
	double * p3 = _getVertex(3);

	double pnt[3] = {p[0], p[1], p[2]};
	/*double p0[3] = {pnt0[0], pnt0[1], pnt0[2]};	// Defunct code
	double p1[3] = {pnt1[0], pnt1[2], pnt1[2]};
	double p2[3] = {pnt2[0], pnt2[1], pnt2[2]};
	double p3[3] = {pnt3[0], pnt3[1], pnt3[2]}; */
	return (steps::math::tet_inside(p0, p1, p2, p3, pnt));
}
Пример #3
0
int obj_load(char *filename, entity_t *e)
{
  if((fp = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "Error loading file: %s\n", filename);
    return -1;
  }
  Vertex vertices[100];
  int faces[100][3];
  
  int nPolygons = 0;
  int vertex_num = 0;
  while((token = _getToken(fp)) != NULL_T) // NULL_T is EOF
  {
    if(token == VERTEX_T) {
      printf("v ");
      _getVertex(&vertices[vertex_num]);
      vertex_num++;
    }
    else if(token == VERTEX_NORM_T) {
      //Vertex *test;
      //printf("vn ");
      //test = _getVertex();
    }
    else if(token == FACE_T) {
      printf("f ");
      int v1, v2, v3;
      _getFace(&v1, &v2, &v3);
      faces[nPolygons][0] = v1;
      faces[nPolygons][1] = v2;
      faces[nPolygons][2] = v3;
      printf("%i %i %i\n", faces[nPolygons][0], v2, v3);
      nPolygons++;
      (e->nPolygons)++;
    }
    else
      ;
  }

  fclose(fp);

  e->nPolygons = nPolygons;
  
  e->pList = (polygon_t *)malloc(nPolygons * sizeof(polygon_t));
  memset(e->pList, 0x0, sizeof(polygon_t));

  for(int i = 0; i < nPolygons; i++) {
    for(int j = 0; j < 3; j++) {
     e->pList[i].v[j].x = vertices[faces[i][j]-1].x;
     e->pList[i].v[j].y = vertices[faces[i][j]-1].y;
     e->pList[i].v[j].z = vertices[faces[i][j]-1].z;
    }
  }
  
  for(int i = 0; i < nPolygons; i++) {
    for(int j = 0; j < 3; j++) {
      printf("poly%i %f %f %f\n", i, e->pList[i].v[j].x,e->pList[i].v[i].y,e->pList[i].v[j].z);
    }
  }

  return 0;
}