/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include //TODO: should we include STL directly in examples? #include "OdaCommon.h" #include "Br/BrBrep.h" #include "AcisBuilder/ISatConverter.h" #include "OdFileBuf.h" #include "MemoryStream.h" #include "Ge/GeCurve3d.h" #include "Ge/GeExtents3d.h" #include "ExSystemServices.h" #include "StaticRxObject.h" #include "HlrAlgoBrep.h" #include "HlrCommonHelpers.h" #include "HlrSatFileData.h" //int main() { #if defined(OD_USE_WMAIN) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif { // I.1 Getting breps from sat file OdArray out; OdStaticRxObject sysServices; odrxInitialize(&sysServices); try { OdRdFileBuf inFile; OdStreamBufPtr pSatBuf; if (argc > 0) { // I.2 Loading .SAT file OdString f(argv[1]); inFile.open(f.c_str()); pSatBuf = &inFile; #ifdef ODA_WINDOWS printf("Proceed file : %ls\n", argv[1]); printf("\n"); #else printf("Proceed file : %s\n", argv[1]); #endif } else // no arguments { // I.2 Creating buffer from char pSatBuf = OdMemoryStream::createNew(); pSatBuf->putBytes(satFileData, (OdUInt32)strlen(satFileData)); } if (!ABBreakToSingleBody(pSatBuf, NULL, true, out)) { printf("Error in ABBreakToSingleBody.\n"); return 0; } if (out.isEmpty()) { printf("File consists of %d bodies. Not enough.\n", out.size()); return 0; } OdBrBrep breps[2]; ISATConverter* pIS = out.first(); breps[0].set(pIS->getIBr()); const int brepsSz = out.size(); if (out.size() > 1) { pIS = out[1]; breps[1].set(pIS->getIBr()); } // II.1 Creating hlrAlgoBrep object OdHlrN::HlrAlgoBrep hlrAlgo; // II.2 Setting view parameters const OdGeVector3d viewDir(-1, -1, -1); hlrAlgo.setViewParams(viewDir, NULL, NULL, NULL); if (brepsSz > 1) { // III.1 Creating a block-like hierarchy of bodies OdGeExtents3d extents; OdHlrN::calculateBrepBox(breps[0], nullptr, extents); OdHlrN::calculateBrepBox(breps[1], nullptr, extents); const OdGeVector3d extDiag = extents.diagonal(); const OdGeVector3d transl(extDiag.x, extDiag.y * 0.75, extDiag.z * 0.75); const int maxL = 3; // III.2 Creating blocks with some transformations inside other block OdArray prevBlocks = { hlrAlgo.getTopBlock() }; for (int iL = 0; iL != maxL; iL++) { OdArray curBlocks; int cntBl = iL < maxL - 1 ? 3 : brepsSz; for (int iB = 0; iB != cntBl; iB++) { OdGeVector3d curTransl = OdGeVector3d::kIdentity; if (iL < maxL - 1) { if (iB > 0) { curTransl[iB] = transl[iB] * (iL + 1) / maxL; } else { curTransl = transl * (iL + 1) / maxL; } } OdGeMatrix3d transf = OdGeMatrix3d::translation(curTransl); curBlocks.push_back(hlrAlgo.createBlock(transf, prevBlocks[0])); } // III.3 Sharing content between created blocks if (iL >= 0 && iL < maxL - 1) { for (int i = 1; i != curBlocks.size(); i++) { OdHlrN::HlrAlgoBrep::shareBlockContent(curBlocks[0], curBlocks[i]); } } else { // III.4 Adding breps to blocks for (int i = 0; i != curBlocks.size(); i++) { hlrAlgo.addBrep(breps[i], curBlocks[i]); } } prevBlocks = curBlocks; } } else // only one body { // III.2 No blocks are created just adding breps as is for (int i = 0; i != brepsSz; i++) { hlrAlgo.addBrep(breps[i]); } } // IV. Run the algorithm OdHlrN::HlrAlgoBrep::Options opts; bool algoResult = hlrAlgo.run(opts); if (!algoResult) { printf("Hlr failed.\n"); return 0; } printf("Hlr completed successfully.\n"); // V. Get the result OdGeCurve3dPtrArray visCrvs3d; OdGeCurve3dPtrArray hidCrvs3d; hlrAlgo.getHlrProjCurves3d(visCrvs3d, &hidCrvs3d); OdGeCurve3dPtrArray* pArrs[2]; pArrs[0] = &visCrvs3d; pArrs[1] = &hidCrvs3d; for (int i = 0; i != 2; i++) { int cntLinear = 0; int cntArc = 0; int cntNurbs = 0; for (int j = 0; j != pArrs[i]->size(); j++) { OdGeCurve3dPtr crv = (*pArrs[i])[j]; if (crv->type() == OdGe::kLineSeg3d) { cntLinear++; } else if (crv->type() == OdGe::kCircArc3d || crv->type() == OdGe::kEllipArc3d) { cntArc++; } else { cntNurbs++; } } OdString str = (i == 0) ? L"Visible curves:" : L"Hidden curves:"; printf("%ls", str.c_str()); printf("\n"); printf("There are %d linear segments;\n", cntLinear); printf("There are %d circular and elliptical arcs;\n", cntArc); printf("There are %d nurbs;\n", cntNurbs); printf("\n"); } } catch (const OdError_FileException& err) { printf("File error : %ls\n", err.description().c_str()); } catch (const OdError&) { printf("Internal error\n"); } for (OdUInt32 f = 0; f < out.size(); ++f) { ABDeleteConverter(out[f]); } out.clear(); odrxUninitialize(); return 0; }