Пример #1
0
    Model::Model(std::string path, bool optimize)
    {
	dbgl::OBJMeshLoader loader;
	loader.setNormalCompatibilityAngle(std::numeric_limits<float>::max());
	m_pMesh = dbgl::Mesh::load(loader, path, optimize ? dbgl::Mesh::Optimize : 0);
	analyzeMesh();

	std::random_device rd;
	m_random.seed(rd());
    }
Пример #2
0
    Model::Model()
    {
	// If no path is specified use a plane. This is just for testing
	// purposes where we don't want to load a file from HD.
	m_pMesh = dbgl::Mesh::makePlane(0);
	analyzeMesh();

	std::random_device rd;
	m_random.seed(rd());
    }
Пример #3
0
    double Model::translateRandom(double maxTranslation, double minTranslation)
    {
	std::uniform_real_distribution<double> rand_double_min_max(minTranslation, maxTranslation);
	double translation = rand_double_min_max(m_random);
	Eigen::Vector3d translationVec = Eigen::Vector3d::Random();
	translationVec.normalize();
	translationVec *= translation;
	for(unsigned int i = 0; i < m_pMesh->vertices().size(); i++)
	    m_pMesh->vertices()[i].translate(translationVec[0], translationVec[1], translationVec[2]);
	analyzeMesh();
	return translation;
    }
Пример #4
0
    void Model::addHole()
    {
	// Initialize random number generator
	std::uniform_int_distribution<uint32_t> rand_uint_0_vertices(0, getAmountOfVertices() - 1);
	// Generate index of vertex to remove
	auto index = rand_uint_0_vertices(m_random);
	// Note: we need to iterate from high indices to low indices since every removed vertex will invalidate
	// every other vertex with an index higher than their own index. Indices are then regenerated in analyzeMesh().
	for(auto it = m_vertices[index].baseVertices.rbegin(); it != m_vertices[index].baseVertices.rend(); ++it)
	    m_pMesh->removeVertex(*it);
	analyzeMesh();
    }
Пример #5
0
    double Model::rotateRandom(double maxAngle, double minAngle)
    {
	std::uniform_real_distribution<double> rand_double_min_max(minAngle, maxAngle);
	double angle = rand_double_min_max(m_random);
	std::uniform_int_distribution<short> rand_bool(0, 1);
	bool flipSign = rand_bool(m_random);
	if(flipSign)
	    angle = -angle;
	Eigen::Vector3d axis = Eigen::Vector3d::Random();
	axis.normalize();
	Eigen::AngleAxis<double> aa(angle, axis);
	Eigen::Quaterniond quat(aa);
	for(unsigned int i = 0; i < getAmountOfVertices(); i++)
	{
	    auto coords = getVertex(i).coords;
	    coords = quat * coords;
	    auto normal = getVertex(i).normal;
	    normal = quat * normal;
	    setVertex(i, coords, normal);
	}
	analyzeMesh();
	return angle;
    }
Пример #6
0
void MeshDXF::loadMesh(const char *path)
{
	FILE *stream; 
	stream = fopen(path, "r");
	if (stream != NULL)	fclose( stream );
	else
	{
		fprintf(stderr,"ERROR: File not found!\n");
		return;
	}

	dimeInput in;
	if (path == NULL) 
	{
		if (!in.setFileHandle(stdin)) 
		{
			fprintf(stderr,"ERROR: Unexpected error opening file from stdin\n");
			return;
		}
	}
	else 
	{
		if (!in.setFile(path)) 
		{
			fprintf(stderr,"ERROR: Error opening file for reading: %s\n",path );
			return;
		}
	}

	dimeModel model;
	if (!model.read(&in)) 
	{
		fprintf(stderr,"ERROR: DXF read error in line: %d\n", in.getFilePosition());
		return;
	}

	// delete old vertices
	if(vertexCount!=0)
	{
		printf("deleting old vertices\n");
		delete [] vertices;
		vertexCount=0;
	}

	tempIndex = 0;
	traverseEntitiesCounting(model);
	traverseBlocksCounting(model);
	vertexCount = tempIndex;
	vertices = new float[vertexCount*3];
	for(int i=0; i<vertexCount*3; i++)
	{
		vertices[i] = 0.0f;
	}
	printf("tempIndex=%i\n",tempIndex);
	tempIndex = 0;
	traverseEntitiesProcessing(model);
	traverseBlocksProcessing(model);

	analyzeMesh();

	meshType = Mesh::MESH_TYPE_QUADS;
	vertexPerFace = 4;
}
Пример #7
0
    void Model::refresh()
    {
	analyzeMesh();
    }