示例#1
0
void Shape::OptimizeRotation()
{
  // CenterAroundXY();
  vector<Vector3d> normals = getMostUsedNormals();
  // cycle through most-used normals?

  Vector3d N;
  Vector3d Z(0,0,-1);
  double angle=0;
  int count = (int)normals.size();
  for (int n=0; n < count; n++) {
    //cerr << n << normals[n] << endl;
    N = normals[n];
    angle = acos(N.dot(Z));
    if (angle>0) {
      Vector3d axis = N.cross(Z);
      if (axis.squared_length()>0.1) {
	Rotate(axis,angle);
	break;
      }
    }
  }
  CalcBBox();
  PlaceOnPlatform();
}
示例#2
0
void Shape::mirror()
{
  const Vector3d mCenter = transform3D.getInverse() * Center;
  for (uint i = 0; i < triangles.size(); i++)
    triangles[i].mirrorX(mCenter);
  CalcBBox();
}
示例#3
0
// Constructor
Shape::Shape()
  : slow_drawing(false), gl_List(-1)
{
  Min.set(0,0,0);
  Max.set(200,200,200);
  CalcBBox();
}
示例#4
0
void Shape::Scale(double in_scale_factor, bool calcbbox)
{
  transform3D.move(-Center);
  transform3D.scale(in_scale_factor);
  transform3D.move(Center);
  if (calcbbox)
    CalcBBox();
}
示例#5
0
void Shape::makeHollow(double wallthickness)
{
  invertNormals();
  const Vector3d wall(wallthickness,wallthickness,wallthickness);
  Matrix4d invT = transform3D.getInverse();
  vector<Triangle> cubet = cube(invT*Min-wall, invT*Max+wall);
  triangles.insert(triangles.end(),cubet.begin(),cubet.end());
  CalcBBox();
}
示例#6
0
// Constructor
Shape::Shape()
{
	Min.x = Min.y = Min.z = 0.0;
	Max.x = Max.y = Max.z = 200.0;
	scale_factor_x = 1;
	scale_factor_y = 1;
	scale_factor_z = 1;
	scale_factor = 1;
	CalcBBox();
}
示例#7
0
// this is primitive, it just rotates triangle vertices
void Shape::Twist(double angle)
{
  CalcBBox();
  double h = Max.z()-Min.z();
  double hangle=0;
  Vector3d axis(0,0,1);
  int count = (int)triangles.size();
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)
#endif
  for (int i=0; i<count; i++) {
    for (size_t j=0; j<3; j++)
      {
	hangle = angle * (triangles[i][j].z() - Min.z()) / h;
	triangles[i][j] = triangles[i][j].rotate(hangle,axis);
      }
    triangles[i].calcNormal();
  }
  CalcBBox();
}
示例#8
0
// Constructor
Shape::Shape()
  : slow_drawing(false)
{
	Min.x = Min.y = Min.z = 0.0;
	Max.x = Max.y = Max.z = 200.0;
	scale_factor_x = 1;
	scale_factor_y = 1;
	scale_factor_z = 1;
	scale_factor = 1;
	CalcBBox();
}
示例#9
0
void C_MeshGroup::Add(C_TriMesh* triMesh)
{
	meshes.push_back(triMesh);

	nPolys += triMesh->GetNPolys();
	nVertices += triMesh->GetNVertices();
	nTriMeshes++;

	CalcBBox();
	CalcBSphere();
}
示例#10
0
void Shape::setTriangles(const vector<Triangle> &triangles_)
{
  triangles = triangles_;

  CalcBBox();
  double vol = volume();
  if (vol < 0) {
    invertNormals();
    vol = -vol;
  }

  //PlaceOnPlatform();
  cerr << _("Shape has volume ") << volume() << _(" mm^3 and ")
       << triangles.size() << _(" triangles") << endl;
}
示例#11
0
void Shape::addTriangles(const vector<Triangle> &tr)
{
  triangles.insert(triangles.end(), tr.begin(), tr.end());
  CalcBBox();
}
示例#12
0
/*************
 * DESCRIPTION:   sets the new object specs
 * INPUT:         disp     pointer to display structure
 *                pos      translate factor
 *                ox,oy,oz rotate factor
 *                size     scale factor
 * OUTPUT:        none
 *************/
void TEXTURE_OBJECT::SetObject(DISPLAY *disp, VECTOR *pos, VECTOR *ox, VECTOR *oy, VECTOR *oz, VECTOR *size)
{
	CalcBBox();
}
示例#13
0
/* Loads an binary STL file by filename
 * Returns 0 on success and -1 on failure */
int Shape::loadBinarySTL(string filename) {

    if(getFileType(filename) != BINARY_STL) {
        return -1;
    }

    triangles.clear();
    Min.x = Min.y = Min.z = numeric_limits<double>::infinity();
    Max.x = Max.y = Max.z = -numeric_limits<double>::infinity();

    ifstream file;
    file.open(filename.c_str());

    if(file.fail()) {
        cerr << "Error: Unable to open stl file - " << filename << endl;
        return -1;
    }

    /* Binary STL files have a meaningless 80 byte header
     * followed by the number of triangles */
    file.seekg(80, ios_base::beg);
    unsigned int num_triangles;
    unsigned char buffer[4];
    file.read(reinterpret_cast <char *> (buffer), 4);
    // Read platform independent 32-bit little-endian int.
    num_triangles = buffer[0] | buffer[1] << 8 | buffer[2] << 16 | buffer[3] << 24;
    triangles.reserve(num_triangles);

    for(uint i = 0; i < num_triangles; i++)
    {
        double a,b,c;
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d N(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Ax(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Bx(a,b,c);
        a = read_double (file);
        b = read_double (file);
        c = read_double (file);
        Vector3d Cx(a,b,c);

	// done in Triangle
        /* Recalculate normal vector - can't trust an STL file! */
        // Vector3d AA=Cx-Ax;
        // Vector3d BB=Cx-Bx;
	// N = AA.cross(BB).getNormalized();

        /* attribute byte count - sometimes contains face color
            information but is useless for our purposes */
        unsigned short byte_count;
        file.read(reinterpret_cast <char *> (buffer), 2);
	byte_count = buffer[0] | buffer[1] << 8;
	// Repress unused variable warning.
	(void)&byte_count;

        Triangle T(Ax,Bx,Cx);

	//cout << "bin triangle "<< N << ":\n\t" << Ax << "/\n\t"<<Bx << "/\n\t"<<Cx << endl;

        triangles.push_back(T);
    }
    file.close();
    CalcBBox();
    CenterAroundXY();
    scale_factor = 1.0;
    cout << "Shape has volume " << volume() << " mm^3"<<endl;
    return 0;
}
示例#14
0
// Constructor
Shape::Shape()
{
	Min.x = Min.y = Min.z = 0.0;
	Max.x = Max.y = Max.z = 200.0;
	CalcBBox();
}