⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rulest.cc

📁 penMesh is a generic and efficient data structure for representing and manipulating polygonal meshes
💻 CC
📖 第 1 页 / 共 4 页
字号:
	if ((Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(red_hh))).is_valid() &&              MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(red_hh)))).red_halfedge()              == red_hh )	    || (Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh)))).is_valid() 	    && MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh))))).red_halfedge() == red_hh))        {	  // double divided face	  if (MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(red_hh)))).red_halfedge() == red_hh) {	    // first case	    vh[0] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh)));	    vh[1] = Inherited::mesh_.TVH(red_hh);	    vh[2] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(red_hh))));      	    new_vh[0] = Inherited::mesh_.FVH(red_hh);	    new_vh[1] = Inherited::mesh_.add_vertex(zero_point);	    new_vh[2] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(red_hh));	    hh[0] = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(red_hh)));	    hh[1] = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(red_hh));	    hh[2] = Inherited::mesh_.NHEH(red_hh);	    // split one edge	    eh = Inherited::mesh_.EH(red_hh);	    split_edge(hh[1], new_vh[1], _target_state);	    assert(Inherited::mesh_.FVH(hh[2]) == vh[1]);	    assert(Inherited::mesh_.FVH(hh[1]) == vh[0]);	    assert(Inherited::mesh_.FVH(hh[0]) == vh[2]);	    	    if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(hh[1])).is_valid()) {	      temp_hh = Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(hh[1])));	      if (MOBJ(Inherited::mesh_.FH(temp_hh)).red_halfedge() != temp_hh)		halfedge_vector.push_back(temp_hh);	    }	  }			  else {	    // second case	    vh[0] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh)))));	    vh[1] = Inherited::mesh_.TVH(red_hh);	    vh[2] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(red_hh));      	    new_vh[0] = Inherited::mesh_.FVH(red_hh);	    new_vh[1] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh)));	    new_vh[2] = Inherited::mesh_.add_vertex(zero_point);	    hh[0] = Inherited::mesh_.PHEH(red_hh);	    hh[1] = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh))));	    hh[2] = Inherited::mesh_.NHEH(red_hh);	    // split one edge	    eh = Inherited::mesh_.EH(red_hh);	    split_edge(hh[2], new_vh[2], _target_state);	    assert(Inherited::mesh_.FVH(hh[2]) == vh[1]);	    assert(Inherited::mesh_.FVH(hh[1]) == vh[0]);	    assert(Inherited::mesh_.FVH(hh[0]) == vh[2]);	    if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(hh[2])).is_valid()) {	    	      temp_hh = Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(hh[2])));	      if (MOBJ(Inherited::mesh_.FH(temp_hh)).red_halfedge() != temp_hh)		halfedge_vector.push_back(temp_hh);	    }	  }	}	else {	  	  // one time divided face	  vh[0] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(red_hh)));	  vh[1] = Inherited::mesh_.TVH(red_hh);	  vh[2] = Inherited::mesh_.TVH(Inherited::mesh_.NHEH(red_hh));      	  new_vh[0] = Inherited::mesh_.FVH(red_hh);	  new_vh[1] = Inherited::mesh_.add_vertex(zero_point);	  new_vh[2] = Inherited::mesh_.add_vertex(zero_point);	  hh[0] = Inherited::mesh_.PHEH(red_hh);	  hh[1] = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(red_hh));	  hh[2] = Inherited::mesh_.NHEH(red_hh);	  // split two edges	  eh = Inherited::mesh_.EH(red_hh);	  split_edge(hh[1], new_vh[1], _target_state);	  split_edge(hh[2], new_vh[2], _target_state);	  assert(Inherited::mesh_.FVH(hh[2]) == vh[1]);	  assert(Inherited::mesh_.FVH(hh[1]) == vh[0]);	  assert(Inherited::mesh_.FVH(hh[0]) == vh[2]);	  if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(hh[1])).is_valid()) {	    temp_hh = Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(hh[1])));	    if (MOBJ(Inherited::mesh_.FH(temp_hh)).red_halfedge() != temp_hh)	      halfedge_vector.push_back(temp_hh);	  }	  if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(hh[2])).is_valid()) {	    temp_hh = Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(hh[2])));	    if (MOBJ(Inherited::mesh_.FH(temp_hh)).red_halfedge() != temp_hh)	      halfedge_vector.push_back(temp_hh);	  }      	}      }    }    // continue here for all cases	    // flip edge    if (Inherited::mesh_.is_flip_ok(eh)) {            Inherited::mesh_.flip(eh);    }        // search new faces    fh[0] = Inherited::mesh_.FH(hh[0]);    fh[1] = Inherited::mesh_.FH(hh[1]);    fh[2] = Inherited::mesh_.FH(hh[2]);    fh[3] = Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(hh[0])));    assert(_fh == fh[0] || _fh == fh[1] || _fh == fh[2] || _fh == fh[3]);     // init new faces    for (int i = 0; i <= 3; ++i) {      MOBJ(fh[i]).set_state(_target_state);      MOBJ(fh[i]).set_final();      MOBJ(fh[i]).set_position(_target_state, face_position);      MOBJ(fh[i]).set_red_halfedge(Inherited::Mesh::InvalidHalfedgeHandle);    }    // init new vertices and edges    for (int i = 0; i <= 2; ++i) {	      MOBJ(new_vh[i]).set_position(_target_state, zero_point);      MOBJ(new_vh[i]).set_state(_target_state);      MOBJ(new_vh[i]).set_not_final();      Inherited::mesh_.set_point(new_vh[i], (Inherited::mesh_.point(vh[i]) + Inherited::mesh_.point(vh[(i + 2) % 3])) * 0.5);      MOBJ(Inherited::mesh_.EH(hh[i])).set_state(_target_state);      MOBJ(Inherited::mesh_.EH(hh[i])).set_position(_target_state, zero_point);      MOBJ(Inherited::mesh_.EH(hh[i])).set_final();      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.NHEH(hh[i]))).set_state(_target_state);      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.NHEH(hh[i]))).set_position(_target_state, zero_point);      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.NHEH(hh[i]))).set_final();      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(hh[i]))).set_state(_target_state);      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(hh[i]))).set_position(_target_state, zero_point);      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(hh[i]))).set_final();    }    // check, if opposite triangle needs splitting    while (!halfedge_vector.empty()) {      temp_hh = halfedge_vector.back();      halfedge_vector.pop_back();      check_edge(temp_hh, _target_state);    }    assert(MOBJ(fh[0]).state() == _target_state);    assert(MOBJ(fh[1]).state() == _target_state);    assert(MOBJ(fh[2]).state() == _target_state);    assert(MOBJ(fh[3]).state() == _target_state);  }}template<class M>voidTvv4<M>::raise(typename M::VertexHandle& _vh, state_t _target_state){   if (MOBJ(_vh).state() < _target_state)  {    update(_vh, _target_state);    // multiply old position by 4    MOBJ(_vh).set_position(_target_state, MOBJ(_vh).position(_target_state - 1) * 4.0);    MOBJ(_vh).inc_state();  }}template<class M>voidTvv4<M>::raise(typename M::EdgeHandle& _eh, state_t _target_state) {   if (MOBJ(_eh).state() < _target_state)   {    update(_eh, _target_state);    typename M::FaceHandle fh(Inherited::mesh_.FH(Inherited::mesh_.HEH(_eh, 0)));    if (!fh.is_valid())      fh=Inherited::mesh_.FH(Inherited::mesh_.HEH(_eh, 1));    raise(fh, _target_state);    assert(MOBJ(_eh).state() == _target_state);  }}#ifndef DOXY_IGNORE_THIStemplate<class M>voidTvv4<M>::split_edge(typename M::HalfedgeHandle &_hh,                        typename M::VertexHandle   &_vh,                        state_t _target_state) {  typename M::HalfedgeHandle temp_hh;  if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh)).is_valid())   {    if (!MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).final())     {          if (MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).red_halfedge().is_valid())       {        	temp_hh = MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).red_halfedge();      }      else       {	// two cases for divided, but not visited face	if (MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh))))).state()             == MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).state())         {	  temp_hh = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh));	}	else if (MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(_hh))))).state()                  == MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).state())        {	  temp_hh = Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(_hh)); 	}      }    }    else      temp_hh = Inherited::Mesh::InvalidHalfedgeHandle;  }  else    temp_hh = Inherited::Mesh::InvalidHalfedgeHandle;	   // split edge  Inherited::mesh_.split(Inherited::mesh_.EH(_hh), _vh);	    if (Inherited::mesh_.FVH(_hh) == _vh)   {	        MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(_hh))))).set_state(MOBJ(Inherited::mesh_.EH(_hh)).state());    _hh = Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(_hh)));  }  if (Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh)).is_valid()) {	      MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh)))).set_not_final();    MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).set_state(_target_state-1);    MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh)))))).set_state(_target_state-1);    MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).set_not_final();    MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh)))))).set_not_final();    MOBJ(Inherited::mesh_.EH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh)))).set_state(_target_state);    if (temp_hh.is_valid()) {	      MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))).set_red_halfedge(temp_hh);      MOBJ(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh)))))).set_red_halfedge(temp_hh);    }     else {      typename M::FaceHandle         fh1(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh))),        fh2(Inherited::mesh_.FH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh))))));      MOBJ(fh1).set_red_halfedge(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh))));      MOBJ(fh2).set_red_halfedge(Inherited::mesh_.OHEH(Inherited::mesh_.PHEH(Inherited::mesh_.OHEH(_hh))));      const typename M::Point zero_point(0.0, 0.0, 0.0);      MOBJ(fh1).set_position(_target_state - 1, zero_point);      MOBJ(fh2).set_position(_target_state - 1, zero_point);    }  }  // init edges  MOBJ(Inherited::mesh_.EH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh))))).set_state(_target_state - 1);  MOBJ(Inherited::mesh_.EH(Inherited::mesh_.NHEH(Inherited::mesh_.OHEH(Inherited::mesh_.NHEH(_hh))))).set_final();  MOBJ(Inherited::mesh_.EH(_hh)).set_state(_target_state - 1);  MOBJ(Inherited::mesh_.EH(_hh)).set_final();}  template<class M>void Tvv4<M>::check_edge(const typename M::HalfedgeHandle& _hh,                          state_t _target_state) {  typename M::FaceHandle fh1(Inherited::mesh_.FH(_hh)),    fh2(Inherited::mesh_.FH(Inherited::mesh_.OHEH(_hh)));  assert(fh1.is_valid());  assert(fh2.is_valid());  typename M::HalfedgeHandle red_hh(MOBJ(fh1).red_halfedge());    if (!MOBJ(fh1).final()) {    assert (MOBJ(fh1).final() == MOBJ(fh2).final());    assert (!MOBJ(fh1).final());    assert (MOBJ(fh1).red_halfedge() == MOBJ(fh2).red_halfedge());    const typename M::Point zero_point(0.0, 0.0, 0.0);    MOBJ(fh1).set_position(_target_state - 1, zero_point);    MOBJ(fh2).set_position(_target_state - 1, zero_point);    assert(red_hh.is_valid());    if (!red_hh.is_valid()) {      MOBJ(fh1).set_state(_target_state - 1);      MOBJ(fh2).set_state(_target_state - 1);      MOBJ(fh1).set_red_halfedge(_hh);      MOBJ(fh2).set_red_halfedge(_hh);      MOBJ(Inherited::mesh_.EH(_hh)).set_not_final();      MOBJ(Inherited::mesh_.EH(_hh)).set_state(_target_state - 1);    }    else {      MOBJ(Inherited::mesh_.EH(_hh)).set_not_final();      MOBJ(Inherited::mesh_.EH(_hh)).set_state(_target_state - 1);      raise(fh1, _target_state);      assert(MOBJ(fh1).state() == _target_state);    }  }}// -------------------------------------------------------------------- VF ----template<class M>void VF<M>::raise(typename M::FaceHandle& _fh, state_t _target_state) {  if (MOBJ(_fh).state() < _target_state) {    update(_fh, _target_state);    // raise all neighbour vertices to level x-1    typename M::FaceVertexIter            fv_it;    typename M::VertexHandle              vh;    std::vector<typename M::VertexHandle> vertex_vector;    if (_target_state > 1) {      for (fv_it = Inherited::mesh_.fv_iter(_fh); fv_it; ++fv_it) {	vertex_vector.push_back(fv_it.handle());      }      while (!vertex_vector.empty()) {	vh = vertex_vector.back();	vertex_vector.pop_back();	Inherited::prev_rule()->raise(vh, _target_state - 1);      }    }    // calculate new position    typename M::Point position(0.0, 0.0, 0.0);    int                  valence(0);    for (fv_it = Inherited::mesh_.fv_iter(_fh); fv_it; ++fv_it) {      ++valence;      position += fv_it->position(_target_state - 1);    }    position /= valence;    // boundary rule    if (Inherited::number() == Inherited::subdiv_rule()->Inherited::number() + 1 &&         Inherited::mesh_.is_boundary(_fh)                  &&         !MOBJ(_fh).final())      position *= 0.5;    MOBJ(_fh).set_position(_target_state, position);    MOBJ(_fh).inc_state();    assert(_target_state == MOBJ(_fh).state());  }}// -------------------------------------------------------------------- FF ----template<class M>void FF<M>::raise(typename M::FaceHandle& _fh, state_t _target_state) {  if (MOBJ(_fh).state() < _target_state) {    update(_fh, _target_state);    // raise all neighbour faces to level x-1    typename M::FaceFaceIter              ff_it;    typename M::FaceHandle                fh;    std::vector<typename M::FaceHandle>   face_vector;    if (_target_state > 1) {      for (ff_it = Inherited::mesh_.ff_iter(_fh); ff_it; ++ff_it) {	face_vector.push_back(ff_it.handle());      }      while (!face_vector.empty()) {	fh = face_vector.back();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -