示例#1
0
string ProjectionAlgos::getSVG(ExtractionType type, 
                               double tolerance, 
                               XmlAttributes V_style, 
                               XmlAttributes V0_style, 
                               XmlAttributes V1_style, 
                               XmlAttributes H_style, 
                               XmlAttributes H0_style, 
                               XmlAttributes H1_style)
{
    stringstream result;
    SVGOutput output;

    if (!H.IsNull() && (type & WithHidden)) {
        H_style.insert({"stroke", "rgb(0, 0, 0)"});
        H_style.insert({"stroke-width", "0.15"});
        H_style.insert({"stroke-linecap", "butt"});
        H_style.insert({"stroke-linejoin", "miter"});
        H_style.insert({"stroke-dasharray", "0.2,0.1)"});
        H_style.insert({"fill", "none"});
        H_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(H,tolerance);
        result  << "<g";
        for (const auto& attribute : H_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(H)
               << "</g>" << endl;
    }
    if (!HO.IsNull() && (type & WithHidden)) {
        H0_style.insert({"stroke", "rgb(0, 0, 0)"});
        H0_style.insert({"stroke-width", "0.15"});
        H0_style.insert({"stroke-linecap", "butt"});
        H0_style.insert({"stroke-linejoin", "miter"});
        H0_style.insert({"stroke-dasharray", "0.02,0.1)"});
        H0_style.insert({"fill", "none"});
        H0_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(HO,tolerance);
        result  << "<g";
        for (const auto& attribute : H0_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(HO)
               << "</g>" << endl;
    }
    if (!VO.IsNull()) {
        V0_style.insert({"stroke", "rgb(0, 0, 0)"});
        V0_style.insert({"stroke-width", "1.0"});
        V0_style.insert({"stroke-linecap", "butt"});
        V0_style.insert({"stroke-linejoin", "miter"});
        V0_style.insert({"fill", "none"});
        V0_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(VO,tolerance);
        result  << "<g";
        for (const auto& attribute : V0_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(VO)
               << "</g>" << endl;
    }
    if (!V.IsNull()) {
        V_style.insert({"stroke", "rgb(0, 0, 0)"});
        V_style.insert({"stroke-width", "1.0"});
        V_style.insert({"stroke-linecap", "butt"});
        V_style.insert({"stroke-linejoin", "miter"});
        V_style.insert({"fill", "none"});
        V_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(V,tolerance);
        result  << "<g";
        for (const auto& attribute : V_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(V)
               << "</g>" << endl;
    }
    if (!V1.IsNull() && (type & WithSmooth)) {
        V1_style.insert({"stroke", "rgb(0, 0, 0)"});
        V1_style.insert({"stroke-width", "1.0"});
        V1_style.insert({"stroke-linecap", "butt"});
        V1_style.insert({"stroke-linejoin", "miter"});
        V1_style.insert({"fill", "none"});
        V1_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(V1,tolerance);
        result  << "<g";
        for (const auto& attribute : V1_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(V1)
               << "</g>" << endl;
    }
    if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
        H1_style.insert({"stroke", "rgb(0, 0, 0)"});
        H1_style.insert({"stroke-width", "0.15"});
        H1_style.insert({"stroke-linecap", "butt"});
        H1_style.insert({"stroke-linejoin", "miter"});
        H1_style.insert({"stroke-dasharray", "0.09,0.05)"});
        H1_style.insert({"fill", "none"});
        H1_style.insert({"transform", "scale(1,-1)"});
        BRepMesh_IncrementalMesh(H1,tolerance);
        result  << "<g";
        for (const auto& attribute : H1_style)
            result << "   " << attribute.first << "=\"" 
                   << attribute.second << "\"\n";
        result << "  >" << endl
               << output.exportEdges(H1)
               << "</g>" << endl;
    }
    return result.str();
}
std::string ProjectionAlgos::getSVG(ExtractionType type, float scale, float tolerance)
{
    std::stringstream result;
    SVGOutput output;
    float hfactor = 0.5f; // hidden line size factor, was 0.15f / 0.35f;

    if (!H.IsNull() && (type & WithHidden)) {
        float width = hfactor * scale;
        BRepMesh::Mesh(H,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   stroke-dasharray=\"0.2,0.1\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(H)
                << "</g>" << endl;
    }
    if (!HO.IsNull() && (type & WithHidden)) {
        float width = hfactor * scale;
        BRepMesh::Mesh(HO,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   stroke-dasharray=\"0.02,0.1\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(HO)
                << "</g>" << endl;
    }
    if (!VO.IsNull()) {
        float width = scale;
        BRepMesh::Mesh(VO,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(VO)
                << "</g>" << endl;
    }
    if (!V.IsNull()) {
        float width = scale;
        BRepMesh::Mesh(V,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(V)
                << "</g>" << endl;
    }
    if (!V1.IsNull() && (type & WithSmooth)) {
        float width = scale;
        BRepMesh::Mesh(V1,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(V1)
                << "</g>" << endl;
    }
    if (!H1.IsNull() && (type & WithSmooth) && (type & WithHidden)) {
        float width = hfactor * scale;
        BRepMesh::Mesh(H1,tolerance);
        result  << "<g" 
                //<< " id=\"" << ViewName << "\"" << endl
                << "   stroke=\"rgb(0, 0, 0)\"" << endl 
                << "   stroke-width=\"" << width << "\"" << endl
                << "   stroke-linecap=\"butt\"" << endl
                << "   stroke-linejoin=\"miter\"" << endl
                << "   stroke-dasharray=\"0.09,0.05\"" << endl
                << "   fill=\"none\"" << endl
                << "  >" << endl
                << output.exportEdges(H1)
                << "</g>" << endl;
    }
        /*result << "0"          << endl
        << "SECTION"  << endl
        << "2"          << endl
        << "ENTITIES" << endl;*/
    return result.str();
}