예제 #1
0
void DeformationGraph::moveFromFaceToVertex(GraphNode* pnode, const PointWithID& pwid)
{
	typedef DeformableMesh3d::InterMesh InterMesh;
	InterMesh* pMesh = dmesh.pMesh;

	InterMesh::FaceHandle fh(pwid.id);
	InterMesh::FaceVertexIter fv_it(pMesh->fv_iter(fh));
	double minDis = 10e8;
	for (; fv_it; ++fv_it) {
		InterMesh::Point& p = pMesh->point(fv_it);
		P3d p3d = P3d(p[0], p[1], p[2]);
		double d = (p3d - pwid.p).mag();
		if (d < minDis) {
			pnode->g = p3d;
			pnode->vertexID = fv_it.handle().idx();
			minDis = d;
		}
	}
}
예제 #2
0
파일: sr_renderer.cpp 프로젝트: kihoku/SRay
void Renderer::build()
{
	_vp.s = 0.0625;
	_vp.width = 640;
	_vp.height = 480;
	_vp.numSamples = 4;

	auto sphere1 = std::make_shared<Sphere>(P3d(1e5 + 1.0, 40.8, 81.6), 1e5);
	auto sphere2 = std::make_shared<Sphere>(P3d(-1e5 + 99.0, 40.8, 81.6), 1e5);
	auto sphere3 = std::make_shared<Sphere>(P3d(50.0, 40.8, 1e5), 1e5);
	auto sphere4 = std::make_shared<Sphere>(P3d(50.0, 40.8, -1e5 + 250.0), 1e5);
	auto sphere5 = std::make_shared<Sphere>(P3d(50.0, 1e5, 81.6), 1e5);
	auto sphere6 = std::make_shared<Sphere>(P3d(50.0, -1e5 + 81.6, 81.6), 1e5);
	//auto sphere7 = std::make_shared<Sphere>(P3d(65.0, 20.0, 20.), 20.0);
	//auto sphere8 = std::make_shared<Sphere>(P3d(27.0, 16.5, 47.), 16.5);
	//auto sphere9 = std::make_shared<Sphere>(P3d(77.0, 16.5, 78.), 16.5);
	auto sphere10 = std::make_shared<Sphere>(P3d(50.0f, 90.0, 81.6), 15.0);
	auto polygon = std::make_shared<TriangleMesh>();
	polygon->loadOBJ("teapod.obj");

	auto mat1 = std::make_shared<Matte>(C3f(0.75f, 0.25f, 0.25f));
	auto mat2 = std::make_shared<Matte>(C3f(0.25f, 0.25f, 0.75f));
	auto mat3 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f));
	auto mat4 = std::make_shared<Matte>(C3f(0.00f, 0.00f, 0.00f));
	auto mat5 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f));
	auto mat6 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f));
	//auto mat7 = std::make_shared<Matte>(C3f(0.25f, 0.75f, 0.25f));
	//auto mat8 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f));
	//auto mat9 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f));
	auto mat10 = std::make_shared<Matte>(C3f(0.0f, 0.00f, 0.00f));
	auto mat11 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f));

	mat1->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat2->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat3->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat4->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat5->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat6->setEmission(C3f(0.0f, 0.0f, 0.0f));
	//mat7->setEmission(C3f(0.0f, 0.0f, 0.0f));
	//mat8->setEmission(C3f(0.0f, 0.0f, 0.0f));
	//mat9->setEmission(C3f(0.0f, 0.0f, 0.0f));
	mat10->setEmission(C3f(36.0f, 36.0f, 36.0f));
	mat11->setEmission(C3f(0.0f, 0.0f, 0.0f));

	sphere1->setMaterial(mat1);
	sphere2->setMaterial(mat2);
	sphere3->setMaterial(mat3);
	sphere4->setMaterial(mat4);
	sphere5->setMaterial(mat5);
	sphere6->setMaterial(mat6);
	//sphere7->setMaterial(mat7);
	//sphere8->setMaterial(mat8);
	//sphere9->setMaterial(mat9);
	sphere10->setMaterial(mat10);
	polygon->setMaterial(mat11);

	_scene.addObject(sphere1);
	_scene.addObject(sphere2);
	_scene.addObject(sphere3);
	_scene.addObject(sphere4);
	_scene.addObject(sphere5);
	_scene.addObject(sphere6);
	//_scene.addObject(sphere7);
	//_scene.addObject(sphere8);
	//_scene.addObject(sphere9);
	_scene.addObject(sphere10);
	_scene.addObject(polygon);

	auto camera = std::make_shared<PinholeCamera>();
	//auto camera = std::make_shared<ThinLens>();
	//camera->setLensRadius(10.0);
	//camera->setFocalDistance(142.0);
	camera->setDistance(40.0);
	_camera = camera;
	_camera->eye = P3d(50.f, 52.f, 220.f);
	_camera->lookat = P3d(50.0f, 51.9f, 219.0f);
	_camera->up = V3d(0.0f, 1.0f, 0.0f);
	_camera->computeUVW();

}
예제 #3
0
void DeformationGraph::GenerateDensePointSet(std::list<PointWithID>& pointcoll, double delta)
{
#ifdef DEBUGTRACE
	meshtalent::DebugTrace dt("./sample.log");
#endif
	assert(pointcoll.size() == 0);

	typedef DeformableMesh3d::InterMesh InterMesh;
	InterMesh* pMesh = dmesh.pMesh;
	int vertexnum = pMesh->n_vertices();
	//int edgenum = pMesh->n_edges();
	//int facetnum = pMesh->n_faces();
	// sample points on vertices.
	InterMesh::VertexIter v_it, v_end(pMesh->vertices_end());
	for (v_it = pMesh->vertices_begin(); v_it != v_end; ++v_it) {
		InterMesh::Point& p = pMesh->point(v_it);
		P3d p3d(p[0], p[1], p[2]);
		pointcoll.push_back(PointWithID(p3d, PointWithID::VERTEX, v_it.handle().idx()));
	}
#ifdef DEBUGTRACE
	dt.Trace("There %d vertex_points sampled.\n", vertexnum);
#endif
	// sample points on edges.
	int epcount = 0;
	InterMesh::EdgeIter e_it, e_end(pMesh->edges_end());
	for (e_it = pMesh->edges_begin(); e_it != e_end; ++e_it) {
		InterMesh::EdgeHandle eh = pMesh->handle(*e_it);
		InterMesh::HalfedgeHandle heh = pMesh->halfedge_handle(eh, 0); // always select the first edge, but if it's a boundary??
		InterMesh::VertexHandle phfrom = pMesh->from_vertex_handle(heh);
		InterMesh::VertexHandle phto = pMesh->to_vertex_handle(heh);
		InterMesh::Point pf = pMesh->point(phfrom);
		InterMesh::Point pt = pMesh->point(phto);
		P3d p3dfrom(pf[0], pf[1], pf[2]);
		P3d p3dto(pt[0], pt[1], pt[2]);
		double dist = (p3dto - p3dfrom).mag();
		//compute delta vector and sample on this edge.
		V3d deltaV = (p3dto - p3dfrom) * delta;
		int times = static_cast<int>(dist / delta) - 1;
		P3d p3dnow = p3dfrom;
		for (int j = 0; j < times; ++j) {
			p3dnow += deltaV;
			pointcoll.push_back(PointWithID(p3dnow, PointWithID::EDGE, e_it.handle().idx()));
		}
		epcount += (times < 0 ? 0 : times);
	}
#ifdef DEBUGTRACE
	dt.Trace("There are %d edge_points sampled.\n", epcount);
#endif
	// sample points on facet.
	int fpcount = 0;
	InterMesh::FaceIter f_it, f_end(pMesh->faces_end());
	for (f_it = pMesh->faces_begin(); f_it != f_end; ++f_it) {
		P3d trivertices[3];
		//assert((*f_it).is_triangle());
		InterMesh::FaceVertexIter fv_it(pMesh->fv_iter(f_it.handle()));
		int j = 0;
		for (; fv_it; ++fv_it, ++j) {
			InterMesh::Point& p = pMesh->point(fv_it);
			trivertices[j] = P3d(p[0], p[1], p[2]);
		}
		// compute num should be sampled.
		V3d v1 = trivertices[1] - trivertices[0];
		V3d v2 = trivertices[2] - trivertices[0];
		//double lenv1 = v1.mag();
		//double lenv2 = v2.mag();
		double area = (v1 % v2).mag() / 2;
		int samplenum = static_cast<int>(area / (delta * delta));
		fpcount += samplenum;
		RandDoubleGenerator drand;
		drand.srand(time(NULL));
		while (samplenum > 0) {
			double lamada1 = drand(0, 1);
			double lamada2 = drand(0, 1);
			if (lamada1 + lamada2 >= 1) { // judge if this point is not in triangle.
				continue;
			}
			P3d tp3d = trivertices[0] + (v1 * lamada1 + v2 * lamada2);
			pointcoll.push_back(PointWithID(tp3d, PointWithID::FACE, f_it.handle().idx()));
			--samplenum;
		} // end of while.
	} // end of for.
#ifdef DEBUGTRACE
	dt.Trace("There are %d facet_points sampled.\n", fpcount);
	dt.Trace("There are %d points sampled totally.\n", pointcoll.size());
#endif
}