예제 #1
0
DecimationModel::DecimationModel()
    : MeshModel()
{
    vertex_optimal_placement = false;

    meshtype_toberendered_ = ORIGINAL;

    is_view_fitting_error_of_mesh2_ = false;
    is_view_fitting_error_of_sm_ = false;


    mesh_.add_property(vp_eval_pos_); //为后面的evaluation做prepare.
    mesh_.add_property(vp_eval_);
    mesh_.add_property(vp_closest_pos_);
    mesh_.add_property(vp_closest_);
    mesh_.add_property(vp_project_pos_);
    mesh_.add_property(vp_project_);
    for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
        mesh_.property(vp_eval_, v_it) = false;
        mesh_.property(vp_closest_, v_it) = false;
    }
    mesh_.add_property(vp_fitting_error_);

    fitting_terminate_ = false;
    DecimationModel::currentDV = this;
}
예제 #2
0
파일: binary.c 프로젝트: berkus/lang-e
/* array from 0..n-1, return position or -1 */
hash_ptr mksearch(int n, int *x) {
	static v_code insn[1024];
	v_reg_type val;

	v_lambda("bin-search", "%i", &val, V_LEAF, insn, sizeof insn);
		gen(x, val, 0, n-1, n/2);
	return (hash_ptr)v_end(0).i;
}
예제 #3
0
파일: ctest.c 프로젝트: berkus/lang-e
int main() { 
	static unsigned insn[1000];
	v_reg_type r;
	struct v_cstate c;
	v_vptr vp;

	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_getreg(&r, V_I, V_TEMP);

	v_push_init(&c);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
	v_seti(r, 10);
	v_push_argi(&c, r);
	v_seti(r,20);
	v_push_argi(&c, r);
	v_seti(r,30);
	v_push_argi(&c, r);
	v_seti(r,40);
	v_push_argi(&c, r);
	v_ccallv(&c, (v_vptr)printf);
	vp = v_end(0).v;
#if 0
	v_dump((void*)vp);
#endif
	vp();

	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_push_init(&c);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
	v_push_argii(&c, 10);
	v_push_argii(&c, 20);
	v_push_argii(&c, 30);
	v_push_argii(&c, 40);
	v_ccallv(&c, (v_vptr)printf);
	vp = v_end(0).v;
#if 0
	v_dump((void*)vp);
#endif
	vp();

#if 0
	v_clambda("foo", V_NLEAF, insn, sizeof insn);
	v_push_argpi(&c, "Hello: %d %d %d %d\n");
#endif
	return 0;
}
예제 #4
0
파일: dcg.c 프로젝트: berkus/lang-e
/* driver */
static void scale(int n, data_t **a, data_t **b, data_t c) {
	struct v_reg  dst,src, src_end, v0, v1, al[10];
	struct v_label  loop1; 
	static unsigned insn[1024];
	v_vptr vp;

	/* simple unroll */
	/* assert(n >= 4 && (n % 4) == 0); */

	v_lambda("foo", "%p%p", al, V_LEAF, insn);

	/* row & c come in as parameters */
	dst 	= al[0];
	src 	= al[1];
	if(!v_getreg(&src_end, V_P, V_TEMP))
		v_fatal("scale: out of registers\n");
	if(!v_getreg(&v0, V_U, V_TEMP))
		v_fatal("scale: out of registers\n");
	if(!v_getreg(&v1, V_U, V_TEMP))
		v_fatal("scale: out of registers\n");

	loop1	= v_genlabel();

	/* relies on contigous memory */
	v_raw_load(v_ldpi(src, src, (0)), 1);	/* perform loads without interlocks */
	v_raw_load(v_ldpi(dst, dst, (0)), 1);
	v_addpi(src_end, src, (n * n) * sizeof **a);

	v_label(loop1);
		/* load 2 to get rid of delay slots */
		v_raw_load(v_ldui(v0, src, (0 * sizeof **a)), 1);
		v_raw_load(v_ldui(v1, src, (1 * sizeof **a)), 1);

		/* multiplies will be strength reduced */
		if(strength_reduce) cmuli(v0, v0, c);
		else		   v_mului(v0, v0, c);

		v_addpi(dst, dst, (2 * sizeof **a));

		if(strength_reduce) cmuli(v1, v1, c);
		else		   v_mului(v1, v1, c);

		v_stui(v0, dst, -(2 * sizeof **a));
		v_addpi(src, src, (2 * sizeof **a));
	/* schedule delay slot instructions */
	v_schedule_delay(
		v_bltp(src, src_end, loop1),
		v_stui(v1, dst, -(1 * sizeof **a))
	);

	vp = v_end().v;
	if(disass)
		v_dump((void *)vp);
	if(!pixie)
		vp(a,b);	/* perform multiplication */
}
예제 #5
0
파일: hello-push.c 프로젝트: berkus/lang-e
int main(void) {
	struct v_cstate c;

	/* Create a function to print standard greeting. */
        v_lambda("hello-world", "", 0, V_NLEAF, malloc(512), 512);
		v_push_init(&c);
		v_push_argpi(&c, "hello, world\n");
		v_ccallv(&c, (v_vptr)printf);
        v_end(0).v(); 	/* Compile & call */
	return 0;
}
예제 #6
0
int main(void) {
	static v_code insn[1000]; 	/* Memory to hold code in. */

        /* Test jump and link instruction */
        v_lambda("jump-and-link", "", 0, V_NLEAF, insn, sizeof insn);
        {
                static v_code *linked_addr;
                v_reg_type rdp, rr;
                v_label_type l;

		/* Allocate two registers persistent accross procedure calls. */
                v_getreg(&rdp, V_P, V_VAR);
		/* Allocate register to hold return pointer */
                v_getreg(&rr, V_P, V_VAR);

                l = v_genlabel(); 	  /* Allocate label */
                v_dlabel(&linked_addr, l); /* mark memory to hold target address */
                v_setp(rdp, &linked_addr); /* Load address */
                v_ldpi(rdp, rdp, 0);

                v_scallv((v_vptr)printf, "%P", "Jumping!\n");
                v_jalp(rr, rdp); 	   /* Jump to it. */

                v_scallv((v_vptr)printf, "%P", "Returning!\n");
                v_retv();		/* Done */

                v_label(l);
                        v_scallv((v_vptr)printf, "%P", "Jumping back!\n");
                        v_jp(rr);	/* Jump back to caller. */
        }
        v_end(0).v();
#if 0
{
	v_vptr vp = v_end(0).v;
	v_dump(vp);
	vp();
}
#endif

	return 0;
}
void MsInterpolation::build_registration_pair()
{
	MyMesh::VertexIter iter, v_end( m_mesh.vertices_end() );

	face_root->pts_index.reserve( m_mesh.n_vertices() );

	int k = 0;
	for (iter = m_mesh.vertices_begin(); iter != v_end; ++iter)
	{
		face_root->pts_index.push_back( iter.handle().idx());
		face_root->r_idx.insert( std::pair<int, int>(iter.handle().idx(), k++) );
	}

	build_registration_pair( face_root );
}
예제 #8
0
파일: power.c 프로젝트: berkus/lang-e
/* Power: raise base to n-th power: n > 0; specialized for a runtime constant n. */
v_fptr specialize_power(int n) {
	v_reg_type x, sum;

        v_lambda("power", "%d", &x, V_LEAF, malloc(512), 512);
	{
		int i;

		/* Allocate accumulator */
		v_getreg(&sum, V_D, V_TEMP);
		v_movf(sum, x);		/* initialize sum */

		/* Specialize power to x^n by unrolling the loop to multiply
	 	   x n times: (x * x * ... * x). */
		for(i = 0; i < n - 1; i++)
			v_mulf(sum, sum, x);

		v_retf(sum);	/* return x ^ n */
	}
        return v_end(0).f;	/* return pointer to result. */
}
void MsInterpolation::test()
{
	while( 1 )
	{
		release_facenode_help(face_root);
		build_hierarchy_on_face();

		printf("最小的节点的点数是:%d\n", min_size_node);

		int min = 0x7fffffff, max = 0;
		max_min_height(face_root, min, max);
		printf("Face min:%d, max:%d\n", min, max);

        if( max < 15)
		{
			break;
		}
	}

	build_registration_pair();

	std::cout<<"Build Pair Done!\n";

	if( BLENDING )
	{
		pre_blending_process(face_root);
		std::cout<<"Pre_blending_process Done!\n";
	}

	build_interpolation(face_root, m_mesh, target_mesh, 0.75);
		
	MyMesh::VertexIter v_iter, v_end( m_mesh.vertices_end());

	for (v_iter = m_mesh.vertices_begin(); v_iter != v_end; ++v_iter)
	{
		MyVector3f v = face_root->pts[ v_iter.handle().idx() ];
		m_mesh.set_point( v_iter, MyMesh::Point( v[0], v[1], v[2]) );
	}

	write_mesh_data( "interpolation_result.off");
}
예제 #10
0
파일: jal-test.c 프로젝트: berkus/lang-e
int main() { 
	static v_code insn[1000];
	v_iptr ip;

        /* jal reg  */
        v_lambda("v_jal", "", 0, V_NLEAF, insn, sizeof insn);
        {
        	static void * linked_addr;
        	v_reg_type rdp;
        	v_reg_type rr;
		v_label_type l;

		v_getreg(&rdp, V_P, V_VAR);
		v_getreg(&rr, V_P, V_VAR);

                l = v_genlabel();
                v_dmark(&linked_addr, l);

                v_ldpi(rdp, v_zero, (unsigned long)&linked_addr);
		v_scallv((v_vptr)printf, "%P", "Jumping!\n");
                v_jalp(rr, rdp);
		v_scallv((v_vptr)printf, "%P", "Returning.\n");	
               	v_retii(13);

                v_label(l);
			v_scallv((v_vptr)printf, "%P", "Jumping back!\n");
			v_jp(rr);
        }
	printf("Testing jalr\n");
	ip = v_end(0).i;
#if 0
	v_dump((void*)ip);
#endif
        if(ip() != 13)
		demand(0, bogus value!);
	return 0;
}
예제 #11
0
bool MeshViewer::OpenMesh(const char* f)
{
	if (OpenMesh::IO::read_mesh(m_Mesh,f)){
		txMesh::ConstVertexIter 
			v_it(m_Mesh.vertices_begin()),
			v_end(m_Mesh.vertices_end());
		txMesh::Point bbMin, bbMax;
		bbMin = bbMax = m_Mesh.point(v_it);
		for (; v_it!=v_end; ++v_it) {
			bbMin.minimize(m_Mesh.point(v_it));
			bbMax.maximize(m_Mesh.point(v_it));
		}
		SetScene( (Vec3f)(bbMin+bbMax)*0.5, 0.5*(bbMin-bbMax).norm());

		m_Mesh.update_normals();

		UpdateFaceIndices();

		return true;
	}

	std::cerr << "read error\n";
	return false;
}
예제 #12
0
파일: vm.c 프로젝트: berkus/lang-e
int main() { 
	static unsigned insn[100];
	v_iptr ip;
	v_reg_type arg_list[10];
	v_label_type l;
	unsigned s2u, s1u;

	s1u =  3422929224;
	s2u = 4205332841;

        /* reg <- (reg < imm) */
        v_lambda("bltuli", "%u", arg_list, V_LEAF, insn, sizeof insn);
                l = v_genlabel();
                v_bltui(arg_list[0], s2u, l);
                        v_retii(0);
                v_label(l);
                        v_retii(1);

        ip = v_end(0).i;

	v_dump((void*)ip);
	printf("ip returned %d, should be %d\n", ((int (*)(unsigned))ip)(s1u), s1u < s2u);
	return 0;
}
예제 #13
0
void DecimationModel::draw() {

    if (meshtype_toberendered_ == ORIGINAL) {


        MeshModel::draw();
    } else if (meshtype_toberendered_ == SIMPLIFIED || meshtype_toberendered_ == RESAMPLE_MIDPOINT) {
        // 第一步, 要是做了参数化的话先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点.
        for (TriMesh::VIter v_it(mesh2_.vertices_begin()), v_end(mesh2_.vertices_end()); v_it != v_end; ++v_it) {
            if ( v_it.handle() == test_vertex_||v_it.handle().idx() == 69000 ) {//|| v_it.handle().idx() == 1493
                glColor3f(0, 1, 0);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(mesh2_.point(v_it));
                glEnd();
                glPointSize(1);
            }
            if (v_it.handle() == test_vertex1_ || v_it.handle().idx() == 56656 || v_it.handle().idx() == 66696 ||v_it.handle().idx() == 203340) {//
                glColor3f(0, 1, 1);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(mesh2_.point(v_it));
                glEnd();
                glPointSize(1);
            }
        }
        for (TriMesh::VIter v_it(initial_control_mesh_.vertices_begin()), v_end(initial_control_mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (v_it.handle() == test_vertex_ ) { //显示新分裂的顶点
                glColor3f(0, 1, 0);
                glPointSize(10);
                glBegin(GL_POINTS);
                GL::glVertex(initial_control_mesh_.point(v_it));
                glEnd();
                glPointSize(1);
            }
        }


        //int fandisk_arr[] = { //这些是一部分特征边
        //	9, 269, 265,
        //	261, 257, 254,
        //	250, 246, 241,
        //	237, 233, 229,
        //	225, 221, 217,
        //	214, 210, 206,
        //	//202, 995, 9762

        //	9922, 9925, 9928,
        //	9931, 9934, 9939,
        //	9943, 9947, 9951,
        //	9954, 9958, 9962,
        //	9966, 9970, 9974,
        //	9978, 9982, 9986,
        //	9990, 9994, 9998,
        //	10002, 10006, 10011,
        //	10014, 784, 788

        //};
        //std::vector<int> fandisk(fandisk_arr, fandisk_arr+18+27);
        //for (int i = 0; i < 45; ++i) {
        //	glColor3f(1, 0, 1); // 显示特征边
        //	glLineWidth(3.5);
        //	glBegin(GL_LINES);
        //	GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 0))));
        //	GL::glVertex(mesh2_.point(mesh2_.to_vertex_handle(mesh2_.halfedge_handle(mesh2_.edge_handle(fandisk_arr[i]), 1))));
        //	glEnd();
        //	glLineWidth(1.0);

        //}

        if (do_parameterization_) {
            //(1) 先显示所有顶点, 包括那些被deleted但是参数化到base complex面上的点.
            // 但是后来我觉得这可以省略, 因为下面显示mesh_collapsed_时候就会显示这些被参数化的点了.
            glDisable(GL_LIGHTING);

            for (TriMesh::EIter e_it(mesh_.edges_begin()), e_end(mesh_.edges_end()); e_it != e_end; ++e_it) {
                if (mesh_.status(e_it).deleted() == false) {
                    if (mesh_.status(e_it).feature()) {
                        glColor3f(1, 0, 1); // 显示特征边
                        glLineWidth(3.5);
                        glBegin(GL_LINES);
                        GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 0))));
                        GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it.handle(), 1))));
                        glEnd();
                        glLineWidth(1.0);/**/

                    }
                    if (meshtype_toberendered_ == RESAMPLE_MIDPOINT) {
                        if (mesh_.property(empl_, e_it.handle()) == true) { //已经求出中点的了.
                            glColor3f(0, 1, 0);//黄色 显示那些采样点
                            glPointSize(4);
                            //glBegin(GL_POINTS);
                            //GL::glVertex(mesh_.property(emp_, e_it.handle()));
                            //glEnd();
                            glPointSize(1);
                            glPushMatrix();
                            glTranslatef( mesh_.property(emp_, e_it.handle())[0], mesh_.property(emp_, e_it.handle())[1], mesh_.property(emp_, e_it.handle())[2] );
                            glutSolidSphere(bb.diagonal_lenght*0.003, 20, 20);
                            glPopMatrix();
                        } else { // 还没有求出中点的
                            glColor3f(0.f, 1.f, 0.f);//绿色 显示那些没有对中点采样成功的边
                            glLineWidth(6.5);
                            glBegin(GL_LINES);
                            GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 0))));
                            GL::glVertex(mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(e_it, 1))));
                            glEnd();
                            glLineWidth(1.0);
                        }
                    } // 如果是中点采样的话显示采样点或不成功的边.
                }
            }

            // (4) 显示被参数化的网格, 作为参考.用hiden line线框模式显示
            if (mesh_collapsed_render_or_not_) {
                DGP::hidderline_render(mesh_collapsed_, OpenMesh::Vec3f(0.0, 0.0, 1.0));
            }

            /////////////////////////////
            //draw_mode_ = HIDDENLINE;//LINEANDSOLIDFLAT; //NONE; // //这里设置了的话用户就不可以选择了.
        } //end of if (do_parameterization_).
        // 第二步, 正常显示.
        MeshModel::draw();
    } else if (meshtype_toberendered_ == REFINED_SIMPLIFIED) {
        //glBegin(GL_POINTS);
        //GL::glColor(OpenMesh::Vec3f(1, 0, 0));
        //glPointSize(3.0);
        //for (TriMesh::FIter f_it(mesh_.faces_begin()), f_end(mesh_.faces_end()); f_it != f_end; ++f_it) {
        //	for (std::vector<TriMesh::VHandle>::const_iterator it(mesh_.property(fvset_, f_it.handle()).begin()), it_end(mesh_.property(fvset_, f_it.handle()).end());
        //		it != it_end; ++it) {
        //			if (32 == mesh_.property(vf_of_rsm_, *it).idx())
        //			GL::glVertex(refined_simplified_mesh_.point(mesh_.property(vf0_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[0]
        //			+ refined_simplified_mesh_.point(mesh_.property(vf1_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[1]
        //			+ refined_simplified_mesh_.point(mesh_.property(vf2_of_rsm_, *it)) * mesh_.property(vbc_of_rsm_, *it)[2]);

        //	}
        //}glPointSize(1);
        //glEnd();
        MeshModel::draw();
    } else if (meshtype_toberendered_ == INITIAL_CONTROL ||meshtype_toberendered_ == LOOP_ONE
               || meshtype_toberendered_ == LIMIT) {

        if (upperbounding_mesh_.n_vertices()) {
            //if (upperbounding_mesh_.empty() == false) {// renc: 20150829
            DGP::hidderline_render(upperbounding_mesh_, OpenMesh::Vec3f(0, 0, 1));
            DGP::hidderline_render(lowerbounding_mesh_, OpenMesh::Vec3f(0, 1, 0));
        }
        glBegin(GL_LINES);
        glLineWidth(3);
        glColor3f(1, 0, 0);
        for (int i = 0; i < laplacian_.size(); ++i) {
            TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i);
            GL::glVertex(refined_simplified_mesh_.point(vh));
            GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_[i]);
        }
        glColor3f(0, 1, 0);
        for (int i = 0; i < laplacian_rcm_.size(); ++i) {
            TriMesh::VHandle vh = refined_simplified_mesh_.vertex_handle(i);
            GL::glVertex(refined_simplified_mesh_.point(vh));
            GL::glVertex(refined_simplified_mesh_.point(vh) + laplacian_rcm_[i]);
        }
        glEnd();
        // 下面画出采样点到evaluation坐标的连线, 也画出到closest坐标的连线, 可视化比较是否离采样点近了.
        glLineWidth(4);
        glBegin(GL_LINES);
        GL::glColor(OpenMesh::Vec3f(0, 1, 0));
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) { //原始网格的点到其在极限曲面上的位置的连线
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_eval_, v_it)) {
                        GL::glVertex(mesh_.property(vp_eval_pos_, v_it.handle()));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        GL::glColor(OpenMesh::Vec3f(1, 1, 0));//最近点
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) {
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_closest_, v_it)) {
                        GL::glVertex(mesh_.property(vp_closest_pos_, v_it));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        GL::glColor(OpenMesh::Vec3f(1, 0, 0));//project point
        for (TriMesh::VIter v_it(mesh_.vertices_begin()), v_end(mesh_.vertices_end()); v_it != v_end; ++v_it) {
            if (mesh_.status(v_it).deleted()) {
                if (std::find(vsplit_array_.begin(), vsplit_array_.end(), v_it.handle()) != vsplit_array_.end())
                    if (mesh_.property(vp_project_, v_it)) {
                        GL::glVertex(mesh_.property(vp_project_pos_, v_it));
                        GL::glVertex(mesh2_.point(v_it));
                    }
            }
        }
        glEnd();
        glLineWidth(1);

        if (is_view_fitting_error_of_mesh2_) {
            glDisable(GL_LIGHTING);
            glShadeModel(GL_SMOOTH);

            // 被取代的原因详见MeshViewer::draw(_draw_mode)函数
            glEnableClientState(GL_VERTEX_ARRAY);
            glEnableClientState(GL_NORMAL_ARRAY);
            glEnableClientState(GL_COLOR_ARRAY);
            GL::glVertexPointer(mesh2_.points());
            GL::glNormalPointer(mesh2_.vertex_normals());
            GL::glColorPointer(mesh2_.vertex_colors());

            glDrawElements(GL_TRIANGLES, mesh2_indices_for_render_.size(), GL_UNSIGNED_INT, &mesh2_indices_for_render_[0]);

            glDisableClientState(GL_VERTEX_ARRAY);
            glDisableClientState(GL_NORMAL_ARRAY);
            glDisableClientState(GL_COLOR_ARRAY);
        }
        if (is_view_fitting_error_of_sm_) {
            glDisable(GL_LIGHTING);
            glShadeModel(GL_SMOOTH);

            glBegin(GL_TRIANGLES);
            for (TriMesh::FIter f_it(simplified_mesh_.faces_begin()), f_end(simplified_mesh_.faces_end()); f_it!=f_end; ++f_it) { // 这种方式应该学学啊
                TriMesh::FVIter fv_it = simplified_mesh_.fv_iter(f_it.handle());
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
                ++fv_it;
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
                ++fv_it;
                GL::glColor(simplified_mesh_.property(vp_color_fitting_error_sm_, fv_it));
                GL::glVertex(simplified_mesh_.point(fv_it));
            }
            glEnd();
        }
        MeshModel::draw();
    } else {
        std::cout << "Error: there isn't this render type.\n";
    }

    //draw_mesh2_ =  true;//false;
    if (draw_mesh2_ == true) { // 是否显示原始网格, 为了方便比较.
        DGP::hidderline_render(mesh2_, OpenMesh::Vec3f(1, 0, 0));
    }
}
예제 #14
0
파일: wk.c 프로젝트: aunali1/exopc
/* A predicate is represented as a sum-of-products, that is
   (A1 A2 ... ) OR (B1 B2 ...) OR ...
   where each element in a product (the A?'s and B?'s) are simple
   predicates like v > 10.

   Predicates are represented in memory as an array of wk_term's,
   one term for each immediate, variable, operator, conjunction or
   disjunction. A single product is considered to be a group of
   contiguous wk_term's that are not WK_ORs. The whole mess is
   terminated by a WK_END.  */

#include <vcode/vcode.h>
#include <xok/wk.h>
#include <xok/mmu.h>
#include <xok/sys_proto.h>
#include <xok/kerrno.h>
#include <xok/malloc.h>
#include <xok_include/assert.h>
#include <xok/printf.h>

#ifndef __CAP__
#include <xok/pmapP.h>
#else
#include <xok/pmap.h>
#endif

#define WK_MAX_CODE_BYTES 4096

#define OVERRUN_SAFETY 20
#define OVERRUN_CHECK						\
{								\
  if (v_ip > code + WK_MAX_CODE_BYTES - OVERRUN_SAFETY) {	\
    warn ("wk_compile: out of code space\n");			\
    ret = -E_INVAL;						\
    goto error;							\
  }								\
}

static int next_pp; /* outside function so can be used by cleanup code */
static int wk_compile (struct wk_term *t, int sz, char *code,
		       u_int *pred_pages) {
  int i;
  v_reg_t r1, r2, z, tag;
  v_label_t end_of_term;
  int start_term = 1;
  int op1 = 1;
  cap c;
  struct Ppage *pp;
  u_int ppn;
  int ret = 0;

  next_pp = 0;

  v_lambda ("", "", NULL, 1, code, WK_MAX_CODE_BYTES);
  if (!v_getreg (&r1, V_U, V_TEMP) ||
      !v_getreg (&r2, V_U, V_TEMP) ||
      !v_getreg (&z, V_U, V_TEMP) ||
      !v_getreg (&tag, V_U, V_TEMP))
    panic ("wk_compile: architecture doesn't have enough registers.");

  v_setu (tag, -1);
  v_setu (z, 0);  
  
  for (i = 0; i < sz; i++) {
    if (start_term) {
      end_of_term = v_genlabel ();
      start_term = 0;
    }
    OVERRUN_CHECK;
    switch (t[i].wk_type) {
    case WK_VAR:
      if (next_pp >= WK_MAX_PP-1) {
	warn ("wk_compile: too many pages in predicate\n");
	ret = -E_INVAL;
	goto error;
      }
      if ((ret = env_getcap (curenv, t[i].wk_cap, &c)) < 0) {
	goto error;
      }
      ppn = PGNO((u_int)t[i].wk_var);
      if (!ppn || ppn >= nppage) {
	printf ("at index %d\n", i);
	warn ("wk_compile: invalid physical page\n");
	ret = -E_INVAL;
	goto error;
      }
      pp = ppages_get(ppn);
      switch (Ppage_pp_status_get(pp)) {
      case PP_USER:
	if ((ret = ppage_acl_check(pp,&c,PP_ACL_LEN,0)) < 0) {
	  goto error;
	}
	ppage_pin (pp);
	pred_pages[next_pp++] = ppn;
	break;
      case PP_KERNRO:
	/* user can access pages that each env get's mapped r/o */
	break;
      default:
	printf ("at index %d\n", i);
	warn ("wk_compile: attempt to reference non PP_KERNRO or PP_USER page\n");
	ret = -E_INVAL;
	goto error;
      }
      if (op1) {
	v_ldui (r1, z, (int )ptov (t[i].wk_var));
	op1 = 0;
      } else {
	v_ldui (r2, z, (int )ptov (t[i].wk_var));
	op1 = 1;
      }
      break;
    case WK_IMM:
      if (op1) {
	v_setu (r1, t[i].wk_imm);
	op1 = 0;
      } else {
	v_setu (r2, t[i].wk_imm);
	op1 = 1;
      }
      break;
    case WK_TAG: {
      v_setu (tag, t[i].wk_tag);
      break;
    }
    case WK_OP: {
      switch (t[i].wk_op) {
      case WK_GT: {
	v_bleu (r1, r2, end_of_term); 
	break;
      }
      case WK_GTE: {
	v_bltu (r1, r2, end_of_term); 
	break;
      }
      case WK_LT: {
	v_bgeu (r1, r2, end_of_term);
	break;
      }
      case WK_LTE: {
	v_bgtu (r1, r2, end_of_term); 
	break;
      }
      case WK_EQ: {
	v_bneu (r1, r2, end_of_term);
	break;
      }
      case WK_NEQ: {
	v_bequ (r1, r2, end_of_term);
	break;
      }
      case WK_OR: {
	v_retu (tag);
	v_label (end_of_term);
	start_term = 1; 
	break;
      }
      default: {
	printf ("at index %d\n", i);
	warn ("wk_compile: invalid wk-pred instruction\n");
	ret = -E_INVAL;
	goto error;
      }
      }
      break;
    }
    default:
      printf ("at index %d\n", i);
      warn ("wk_compile: invalid wk-pred type\n");
      ret = -E_INVAL;
      goto error;
    }
  }
      
  /* end the last term */
  OVERRUN_CHECK;
  v_retu (tag);
  v_label (end_of_term);

  v_retui (0);
  v_end (NULL);

error:
  /* have to do this even on error so that our caller can just call
     wk_free to clean memory/ref counts up */
  pred_pages[next_pp] = 0;
  curenv->env_pred_pgs = pred_pages;
  curenv->env_pred = (Spred)code;
  return ret;
}
          bool set_conditions(const std::vector<rib_data_type> &rbs, const std::vector<index_type> &maxd, bool cl=false)
          {
            index_type i, j, nsegs(static_cast<index_type>(maxd.size())), nribs(rbs.size());

            // ensure input vectors are correct size
            if (!cl && (nribs!=(nsegs+1)))
              return false;
            if (cl && (nribs!=nsegs))
              return false;

            // check to make sure have valid end conditions
            if (!cl)
            {
              if (rbs[0].use_left_fp() || rbs[0].use_left_fpp() || rbs[0].get_continuity()!=rib_data_type::C0)
              {
                return false;
              }
              if (rbs[nsegs].use_right_fp() || rbs[nsegs].use_right_fpp() || rbs[nsegs].get_continuity()!=rib_data_type::C0)
              {
                return false;
              }
            }

            // make sure ribs are in valid state
            data_type v_start(rbs[0].get_t0()), v_end(rbs[0].get_tmax());
            tolerance_type tol;
            for (i=0; i<nribs; ++i)
            {
              if (!rbs[i].check_state())
                return false;
              if (!tol.approximately_equal(rbs[i].get_t0(), v_start) || !tol.approximately_equal(rbs[i].get_tmax(), v_end))
                return false;
            }

            // find all unique v-coordinates on joints for each rib
            auto comp = [&tol](const data_type &x1, const data_type &x2)->bool
            {
              return tol.approximately_less_than(x1, x2);
            };

            std::vector<data_type> joints;
            data_type t0(rbs[0].get_t0()), tmax(rbs[0].get_tmax());

            rbs[0].get_joints(std::back_inserter(joints));
            for (i=1; i<nribs; ++i)
            {
              // test to make sure this rib's parameterization matches rest
              if (!tol.approximately_equal(rbs[i].get_t0(), t0) || !tol.approximately_equal(rbs[i].get_tmax(), tmax))
              {
                return false;
              }

              // get the joints on the current rib
              std::vector<data_type> rjoints, jts_out;
              rbs[i].get_joints(std::back_inserter(rjoints));

              // merge these joints with current list of joints
              std::set_union(joints.begin(), joints.end(), rjoints.begin(), rjoints.end(), std::back_inserter(jts_out), comp);
              std::swap(joints, jts_out);
            }

            // record where the joints need to be for create()
            index_type njoints(static_cast<index_type>(joints.size()));

            // set the v-parameterization
            this->set_number_v_segments(njoints-1);
            this->set_initial_v(joints[0]);
            for (j=0; j<(njoints-1); ++j)
            {
              this->set_dv(joints[j+1]-joints[j], j);
            }

            // reset the number of u-segments
            this->set_number_u_segments(nsegs);

            ribs=rbs;
            max_degree=maxd;
            closed=cl;

            return true;
          }
예제 #16
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
}
예제 #17
0
파일: main.c 프로젝트: lichray/nvi2
/*
 * editor --
 *	Main editor routine.
 *
 * PUBLIC: int editor(GS *, int, char *[]);
 */
int
editor(GS *gp, int argc, char *argv[])
{
	extern int optind;
	extern char *optarg;
	const char *p;
	EVENT ev;
	FREF *frp;
	SCR *sp;
	size_t len;
	u_int flags;
	int ch, flagchk, lflag, secure, startup, readonly, rval, silent;
	char *tag_f, *wsizearg, path[256];
	CHAR_T *w;
	size_t wlen;

	/* Initialize the busy routine, if not defined by the screen. */
	if (gp->scr_busy == NULL)
		gp->scr_busy = vs_busy;
	/* Initialize the message routine, if not defined by the screen. */
	if (gp->scr_msg == NULL)
		gp->scr_msg = vs_msg;
	gp->catd = (nl_catd)-1;

	/* Common global structure initialization. */
	TAILQ_INIT(gp->dq);
	TAILQ_INIT(gp->hq);
	SLIST_INIT(gp->ecq);
	SLIST_INSERT_HEAD(gp->ecq, &gp->excmd, q);
	gp->noprint = DEFAULT_NOPRINT;

	/* Structures shared by screens so stored in the GS structure. */
	TAILQ_INIT(gp->frefq);
	TAILQ_INIT(gp->dcb_store.textq);
	SLIST_INIT(gp->cutq);
	SLIST_INIT(gp->seqq);

	/* Set initial screen type and mode based on the program name. */
	readonly = 0;
	if (!strcmp(getprogname(), "ex") || !strcmp(getprogname(), "nex"))
		LF_INIT(SC_EX);
	else {
		/* Nview, view are readonly. */
		if (!strcmp(getprogname(), "nview") ||
		    !strcmp(getprogname(), "view"))
			readonly = 1;
		
		/* Vi is the default. */
		LF_INIT(SC_VI);
	}

	/* Convert old-style arguments into new-style ones. */
	if (v_obsolete(argv))
		return (1);

	/* Parse the arguments. */
	flagchk = '\0';
	tag_f = wsizearg = NULL;
	lflag = secure = silent = 0;
	startup = 1;

	/* Set the file snapshot flag. */
	F_SET(gp, G_SNAPSHOT);

#ifdef DEBUG
	while ((ch = getopt(argc, argv, "c:D:eFlRrSsT:t:vw:")) != EOF)
#else
	while ((ch = getopt(argc, argv, "c:eFlRrSst:vw:")) != EOF)
#endif
		switch (ch) {
		case 'c':		/* Run the command. */
			/*
			 * XXX
			 * We should support multiple -c options.
			 */
			if (gp->c_option != NULL) {
				warnx("only one -c command may be specified.");
				return (1);
			}
			gp->c_option = optarg;
			break;
#ifdef DEBUG
		case 'D':
			switch (optarg[0]) {
			case 's':
				startup = 0;
				break;
			case 'w':
				attach(gp);
				break;
			default:
				warnx("usage: -D requires s or w argument.");
				return (1);
			}
			break;
#endif
		case 'e':		/* Ex mode. */
			LF_CLR(SC_VI);
			LF_SET(SC_EX);
			break;
		case 'F':		/* No snapshot. */
			F_CLR(gp, G_SNAPSHOT);
			break;
		case 'l':		/* Set lisp, showmatch options. */
			lflag = 1;
			break;
		case 'R':		/* Readonly. */
			readonly = 1;
			break;
		case 'r':		/* Recover. */
			if (flagchk == 't') {
				warnx("only one of -r and -t may be specified.");
				return (1);
			}
			flagchk = 'r';
			break;
		case 'S':
			secure = 1;
			break;
		case 's':
			silent = 1;
			break;
#ifdef DEBUG
		case 'T':		/* Trace. */
			if ((gp->tracefp = fopen(optarg, "w")) == NULL) {
				warn("%s", optarg);
				goto err;
			}
			(void)fprintf(gp->tracefp,
			    "\n===\ntrace: open %s\n", optarg);
			break;
#endif
		case 't':		/* Tag. */
			if (flagchk == 'r') {
				warnx("only one of -r and -t may be specified.");
				return (1);
			}
			if (flagchk == 't') {
				warnx("only one tag file may be specified.");
				return (1);
			}
			flagchk = 't';
			tag_f = optarg;
			break;
		case 'v':		/* Vi mode. */
			LF_CLR(SC_EX);
			LF_SET(SC_VI);
			break;
		case 'w':
			wsizearg = optarg;
			break;
		case '?':
		default:
			(void)gp->scr_usage();
			return (1);
		}
	argc -= optind;
	argv += optind;

	/*
	 * -s option is only meaningful to ex.
	 *
	 * If not reading from a terminal, it's like -s was specified.
	 */
	if (silent && !LF_ISSET(SC_EX)) {
		warnx("-s option is only applicable to ex.");
		goto err;
	}
	if (LF_ISSET(SC_EX) && F_ISSET(gp, G_SCRIPTED))
		silent = 1;

	/*
	 * Build and initialize the first/current screen.  This is a bit
	 * tricky.  If an error is returned, we may or may not have a
	 * screen structure.  If we have a screen structure, put it on a
	 * display queue so that the error messages get displayed.
	 *
	 * !!!
	 * Everything we do until we go interactive is done in ex mode.
	 */
	if (screen_init(gp, NULL, &sp)) {
		if (sp != NULL)
			TAILQ_INSERT_HEAD(gp->dq, sp, q);
		goto err;
	}
	F_SET(sp, SC_EX);
	TAILQ_INSERT_HEAD(gp->dq, sp, q);

	if (v_key_init(sp))		/* Special key initialization. */
		goto err;

	{ int oargs[5], *oargp = oargs;
	if (lflag) {			/* Command-line options. */
		*oargp++ = O_LISP;
		*oargp++ = O_SHOWMATCH;
	}
	if (readonly)
		*oargp++ = O_READONLY;
	if (secure)
		*oargp++ = O_SECURE;
	*oargp = -1;			/* Options initialization. */
	if (opts_init(sp, oargs))
		goto err;
	}
	if (wsizearg != NULL) {
		ARGS *av[2], a, b;
		(void)snprintf(path, sizeof(path), "window=%s", wsizearg);
		a.bp = (CHAR_T *)path;
		a.len = strlen(path);
		b.bp = NULL;
		b.len = 0;
		av[0] = &a;
		av[1] = &b;
		(void)opts_set(sp, av, NULL);
	}
	if (silent) {			/* Ex batch mode option values. */
		O_CLR(sp, O_AUTOPRINT);
		O_CLR(sp, O_PROMPT);
		O_CLR(sp, O_VERBOSE);
		O_CLR(sp, O_WARN);
		F_SET(sp, SC_EX_SILENT);
	}

	sp->rows = O_VAL(sp, O_LINES);	/* Make ex formatting work. */
	sp->cols = O_VAL(sp, O_COLUMNS);

	if (!silent && startup) {	/* Read EXINIT, exrc files. */
		if (ex_exrc(sp))
			goto err;
		if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE)) {
			if (screen_end(sp))
				goto err;
			goto done;
		}
	}

	/*
	 * List recovery files if -r specified without file arguments.
	 * Note, options must be initialized and startup information
	 * read before doing this.
	 */
	if (flagchk == 'r' && argv[0] == NULL) {
		if (rcv_list(sp))
			goto err;
		if (screen_end(sp))
			goto err;
		goto done;
	}

	/*
	 * !!!
	 * Initialize the default ^D, ^U scrolling value here, after the
	 * user has had every opportunity to set the window option.
	 *
	 * It's historic practice that changing the value of the window
	 * option did not alter the default scrolling value, only giving
	 * a count to ^D/^U did that.
	 */
	sp->defscroll = (O_VAL(sp, O_WINDOW) + 1) / 2;

	/*
	 * If we don't have a command-line option, switch into the right
	 * editor now, so that we position default files correctly, and
	 * so that any tags file file-already-locked messages are in the
	 * vi screen, not the ex screen.
	 *
	 * XXX
	 * If we have a command-line option, the error message can end
	 * up in the wrong place, but I think that the combination is
	 * unlikely.
	 */
	if (gp->c_option == NULL) {
		F_CLR(sp, SC_EX | SC_VI);
		F_SET(sp, LF_ISSET(SC_EX | SC_VI));
	}

	/* Open a tag file if specified. */
	if (tag_f != NULL) {
		CHAR2INT(sp, tag_f, strlen(tag_f) + 1, w, wlen);
		if (ex_tag_first(sp, w))
			goto err;
	}

	/*
	 * Append any remaining arguments as file names.  Files are recovery
	 * files if -r specified.  If the tag option or ex startup commands
	 * loaded a file, then any file arguments are going to come after it.
	 */
	if (*argv != NULL) {
		if (sp->frp != NULL) {
			/* Cheat -- we know we have an extra argv slot. */
			*--argv = strdup(sp->frp->name);
			if (*argv == NULL) {
				warn(NULL);
				goto err;
			}
		}
		sp->argv = sp->cargv = argv;
		F_SET(sp, SC_ARGNOFREE);
		if (flagchk == 'r')
			F_SET(sp, SC_ARGRECOVER);
	}

	/*
	 * If the ex startup commands and or/the tag option haven't already
	 * created a file, create one.  If no command-line files were given,
	 * use a temporary file.
	 */
	if (sp->frp == NULL) {
		if (sp->argv == NULL) {
			if ((frp = file_add(sp, NULL)) == NULL)
				goto err;
		} else  {
			if ((frp = file_add(sp, sp->argv[0])) == NULL)
				goto err;
			if (F_ISSET(sp, SC_ARGRECOVER))
				F_SET(frp, FR_RECOVER);
		}

		if (file_init(sp, frp, NULL, 0))
			goto err;
		if (EXCMD_RUNNING(gp)) {
			(void)ex_cmd(sp);
			if (F_ISSET(sp, SC_EXIT | SC_EXIT_FORCE)) {
				if (screen_end(sp))
					goto err;
				goto done;
			}
		}
	}

	/*
	 * Check to see if we need to wait for ex.  If SC_SCR_EX is set, ex
	 * was forced to initialize the screen during startup.  We'd like to
	 * wait for a single character from the user, but we can't because
	 * we're not in raw mode.  We can't switch to raw mode because the
	 * vi initialization will switch to xterm's alternate screen, causing
	 * us to lose the messages we're pausing to make sure the user read.
	 * So, wait for a complete line.  
	 */
	if (F_ISSET(sp, SC_SCR_EX)) {
		p = msg_cmsg(sp, CMSG_CONT_R, &len);
		(void)write(STDOUT_FILENO, p, len);
		for (;;) {
			if (v_event_get(sp, &ev, 0, 0))
				goto err;
			if (ev.e_event == E_INTERRUPT ||
			    (ev.e_event == E_CHARACTER &&
			     (ev.e_value == K_CR || ev.e_value == K_NL)))
				break;
			(void)gp->scr_bell(sp);
		}
	}

	/* Switch into the right editor, regardless. */
	F_CLR(sp, SC_EX | SC_VI);
	F_SET(sp, LF_ISSET(SC_EX | SC_VI) | SC_STATUS_CNT);

	/*
	 * Main edit loop.  Vi handles split screens itself, we only return
	 * here when switching editor modes or restarting the screen.
	 */
	while (sp != NULL)
		if (F_ISSET(sp, SC_EX) ? ex(&sp) : vi(&sp))
			goto err;

done:	rval = 0;
	if (0)
err:		rval = 1;

	/* Clean out the global structure. */
	v_end(gp);

	return (rval);
}
예제 #18
0
 NodeStorageBase::iterator NodeStorageBase::end()
 {
   return v_end();
 }