示例#1
0
template <class X> inline void DLIList<X>::intersect ( const DLIList<X>& merge_list )
{
  if ( &merge_list == this )
     return;

  const int itemCount = listArray.size();
  std::vector<X> tmp;

  for ( int i=0; i<itemCount; i++ )
  {
    if (merge_list.is_in_list(listArray[i]))
    {
      tmp.push_back(listArray[i]);
    }
  }

  this->listArray.swap(tmp);
  index = 0;
}
示例#2
0
CubitStatus SimplifyTool::simplify_curves_in_volume(
    DLIList<RefEdge*> ref_edge_list, 
    double angle_in,
    DLIList<RefEdge*> respect_edge_list,
    DLIList<RefVertex*> respect_vertex_list,
    CubitBoolean respect_imprints,
    CubitBoolean local_normals,
    CubitBoolean preview)
{
  if(local_normals){
    PRINT_WARNING("When simplifying curves, 'local_normals' is currently ignored.\n");
  }
  
    if(ref_edge_list.size()==0)
    {
        PRINT_ERROR("No curves specified for simplification\n");
        return CUBIT_FAILURE;
    }
    else if(ref_edge_list.size() == 1)
    {
        PRINT_ERROR("Only one curve specified for simplification\n");
        return CUBIT_FAILURE;
    }

    RefVolume* ref_volume = ref_edge_list.get()->ref_volume();
    if (NULL == ref_volume)
    {
      PRINT_WARNING("Simplifying free curves is not supported.\n"); 
      return CUBIT_FAILURE;
    }

    DLIList<RefEdge*> seed_edges;
    DLIList<RefVertex*> preview_vertices;
    DLIList<RefVertex*> preview_removed;

    if(preview)
        ref_volume->ref_vertices(preview_vertices);

    int j,k;

    int new_edge_count = 0;
    int combined_edge_count = 0;
    ProgressTool *prog_ptr = 0;
    if(ref_edge_list.size() > 100 )
    {
        char title[200];
        if(preview)
            sprintf(title, "Previewing Volume %d",ref_volume->id());
        else
            sprintf(title, "Simplifying Curves in Volume %d",ref_volume->id());

        prog_ptr = AppUtil::instance()->progress_tool();
        assert(prog_ptr != NULL);
        prog_ptr->start(0,100, title);
    }
    int start_edge_count = ref_edge_list.size();
    while(ref_edge_list.size())
    {
        DLIList<RefEdge*> composite_edges;
        seed_edges.append_unique(ref_edge_list.pop());

        for ( j = ref_edge_list.size(); j--; )
            ref_edge_list.get_and_step()->marked( CUBIT_FALSE );

        while(seed_edges.size())
        {
            RefEdge *seed_ref_edge = seed_edges.pop();
            seed_ref_edge->marked(CUBIT_TRUE);

            composite_edges.append(seed_ref_edge);

            // Get the vertices
            DLIList<RefVertex*> ref_vertex_list;
            seed_ref_edge->ref_vertices( ref_vertex_list );
            RefVertex *ref_vertex_ptr;
            RefEdge *ref_edge_ptr;
            for( k = ref_vertex_list.size(); k--; )
            {
                ref_vertex_ptr = ref_vertex_list.get_and_step();

                // Don't go propagate across surface splits if the user asks for it
                GeometryFeatureTool* gft = GeometryFeatureTool::instance();
                if( respect_imprints &&
                    gft->feature_type(ref_vertex_ptr) == GeometryFeatureEngine::FEATURE_IMPRINT)
                    continue;

                // Don't cross a curve if we want it respected
                if(respect_vertex_list.is_in_list(ref_vertex_ptr))
                    continue;

                DLIList<RefEdge*> attached_ref_edges;
                ref_vertex_ptr->ref_edges( attached_ref_edges );

                attached_ref_edges.remove(seed_ref_edge);
                ref_edge_ptr = attached_ref_edges.size()!=0?attached_ref_edges.get():0;

                // keep the face if we want it respected
                if(attached_ref_edges.size() == 1 &&
                    respect_edge_list.is_in_list(attached_ref_edges.get()))
                    continue;

                // Don't consider ref_faces that are already in the list
                if( attached_ref_edges.size() == 1 &&
                    !ref_edge_ptr->marked())
                {
                    DLIList<RefVolume*> ref_volumes;
                    ref_edge_ptr->ref_volumes( ref_volumes );
                    if( !ref_volumes.size() || ref_volumes.size()==1 )
                    {
                        // Only add the ref_face if it meets the feature angle criteria
                        if(composite_curves(seed_ref_edge,ref_edge_ptr,angle_in))
                        {
                          ref_edge_ptr->marked( CUBIT_TRUE );
                          seed_edges.append(ref_edge_ptr);
                          composite_edges.append(ref_edge_ptr);
                        }
                    }
                }
            }
        }
        composite_edges.uniquify_unordered();
        ref_edge_list -= composite_edges;

        if(!preview &&
            composite_edges.size()>1)
        {
            DLIList<RefVertex*> result_vertices;
            DLIList<RefEdge*> result_edges;
            CompositeTool::instance()->composite(
                composite_edges,
                result_edges,
                &result_vertices);

            combined_edge_count +=composite_edges.size();
            for(int m = result_edges.size();m--;)
                result_edges.get_and_step()->marked(CUBIT_TRUE);

            new_edge_count+=result_edges.size();
        }
        else if(preview)
        {
            int edge_count = composite_edges.size();
            for(int i =0;i<edge_count;i++)
            {
                RefEdge* cur_comp_edge = composite_edges[i];
                DLIList<RefVertex*> refvertices; 
                for(int j =0;j<edge_count;j++)
                {
                    if(i==j) continue;
                    composite_edges[j]->ref_vertices(refvertices);
                }

                refvertices.uniquify_unordered();

                DLIList<RefVertex*> temp_refvertices; 
                cur_comp_edge->ref_vertices(temp_refvertices);
                refvertices.intersect_unordered(temp_refvertices);
                preview_removed+=refvertices;
            }
        }

        if(prog_ptr)
        {
            double frac = 1.0-(double)ref_edge_list.size()/(double)start_edge_count;
            prog_ptr->percent(frac);
        }
    }

    if(prog_ptr)
    {
        prog_ptr->end();
        prog_ptr = 0;
    }

    if(preview)
    {
        preview_vertices -=preview_removed;
        for(int c = preview_vertices.size();c--;)
            GfxDebug::draw_ref_vertex(preview_vertices.get_and_step(),7);
    }
    else if(combined_edge_count>new_edge_count)
    {
        PRINT_INFO("Simplified %d curves into %d curves\n",
            combined_edge_count,
            new_edge_count);
	}

	// make sure to set all of the surface markers to false
	DLIList<RefEdge*> marked_edge_list;
	ref_volume->ref_edges(marked_edge_list);
	for(int i =0;i<marked_edge_list.size();i++)
		marked_edge_list[i]->marked(CUBIT_FALSE);

    return CUBIT_SUCCESS;
}