=============== LIBRARY RULES =============== From library maintainers: - Link the shared library (libsimpleOCCTVP.dylib/.so or simpleOCCTVP.dll) and #include src/occt_templot.h. On macOS/Linux pass -lsimpleOCCTVP plus an rpath; on Windows link simpleOCCTVP.lib and put the .dll beside the executable or on PATH. - Every exported symbol uses the cdecl calling convention and is prefixed ot_ (operations) or occt_templot_ (lifecycle). Call occt_templot_init() once before any other function and occt_templot_shutdown() once at exit. - OTShapeRef, OTViewerRef, OTCameraRef, and OTDrawerRef are opaque void* handles owned by the caller. Free each with its destructor: ot_shape_free, ot_viewer_destroy, ot_camera_destroy, ot_drawer_destroy. All destructors are NULL-safe. - Returned structs OTMeshData and OTEdgeMeshData own heap buffers; release them with ot_mesh_free / ot_edge_mesh_free. Importers and healing functions return NULL on failure; read occt_templot_last_error() (thread-local) for the reason. - Offscreen rendering: create a viewer with ot_viewer_create(w,h), add shapes via ot_viewer_add_shape (returns a display id >0), then render with ot_viewer_render, ot_viewer_render_to_buffer, or ot_viewer_save_image. The viewer does not own the shapes. - Set render quality with the CADRays-style knobs over OCCT Graphic3d_RenderingParams: ot_viewer_set_render_preset (DRAFT/BALANCED/PHOTOREALISTIC), ot_viewer_set_rendering_method, ot_viewer_set_path_tracing, and ot_viewer_set_shape_pbr_material. - Document only the real exported functions declared in src/occt_templot.h; the Pascal binding pascal/occt_templot.pas mirrors them one-to-one with cdecl external declarations and adds helpers OTGetLastError, OTShapeTypeName, and OTViewerRenderToBitmap. ### C/C++ Example: Import, Mesh, and Render Shape Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Demonstrates initializing the library, importing a STEP file, getting its bounding box, extracting a triangle mesh, and rendering it to an image. ```c #include "occt_templot.h" int main() { occt_templot_init(); // Import a STEP file OTShapeRef shape = ot_import_step("model.step"); if (!shape) { printf("Error: %s\n", occt_templot_last_error()); return 1; } // Get bounding box double xmin, ymin, zmin, xmax, ymax, zmax; ot_shape_bounding_box(shape, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax); // Extract triangle mesh OTMeshData mesh = ot_mesh_shape(shape, 0.1); printf("Triangles: %d, Vertices: %d\n", mesh.triangle_count, mesh.vertex_count); ot_mesh_free(&mesh); // Offscreen render to PNG OTViewerRef viewer = ot_viewer_create(800, 600); ot_viewer_add_shape(viewer, shape, OT_DISPLAY_SHADED); ot_viewer_fit_all(viewer); ot_viewer_save_image(viewer, "render.png"); ot_viewer_destroy(viewer); ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Runnable Example Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A complete example demonstrating importing a STEP file, checking its type, exporting it as STL, and cleaning up resources. ```APIDOC ## Runnable Example — import, inspect, re-export ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef shape = ot_import_step("model.step"); if (!shape) { printf("import failed: %s\n", occt_templot_last_error()); occt_templot_shutdown(); return 1; } printf("shape type code: %d\n", ot_shape_type(shape)); if (!ot_export_stl(shape, "model.stl", 0.1)) printf("export failed: %s\n", occt_templot_last_error()); ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` ``` -------------------------------- ### Offscreen Render to PNG Example Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Demonstrates how to initialize the library, load a STEP model, set up a viewer with specific rendering parameters, and save the rendered output as a PNG image. This example performs an offscreen render without displaying a window. ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef shape = ot_import_step("model.step"); if (!shape) { occt_templot_shutdown(); return 1; } OTViewerRef viewer = ot_viewer_create(800, 600); int32_t id = ot_viewer_add_shape(viewer, shape, OT_DISPLAY_SHADED); ot_viewer_set_shape_material(viewer, id, "steel"); ot_viewer_set_background_gradient(viewer, 0.2,0.2,0.3, 0.0,0.0,0.0); ot_viewer_set_render_preset(viewer, OT_PRESET_BALANCED); ot_viewer_set_view_orientation(viewer, OT_VIEW_ISO); ot_viewer_fit_all(viewer); if (!ot_viewer_save_image(viewer, "render.png")) printf("render failed: %s\n", occt_templot_last_error()); ot_viewer_destroy(viewer); ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Example Usage Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A basic example demonstrating the initialization, version retrieval, error checking, and shutdown of the library. ```APIDOC ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); printf("simpleOCCTVP %s\n", occt_templot_version()); if (occt_templot_last_error()) printf("error: %s\n", occt_templot_last_error()); occt_templot_shutdown(); return 0; } ``` ``` -------------------------------- ### Pascal Binding Example: Load Mesh and Render Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md An example demonstrating how to use the Free Pascal binding to load a STEP model, extract mesh data, and render it to a bitmap. ```pascal uses occt_templot; procedure LoadMeshAndRender; var shape: OTShapeRef; mesh: OTMeshData; viewer: OTViewerRef; begin occt_templot_init; try shape := ot_import_step('model.step'); if shape = nil then raise Exception.Create('import failed: ' + OTGetLastError) else try mesh := ot_mesh_shape(shape, 0.1); try WriteLn('triangles: ', mesh.triangle_count); finally ot_mesh_free(mesh); end; viewer := ot_viewer_create(800, 600); try ot_viewer_add_shape(viewer, shape, OT_DISPLAY_SHADED); ot_viewer_set_render_preset(viewer, OT_PRESET_BALANCED); ot_viewer_fit_all(viewer); ot_viewer_save_image(viewer, 'render.png'); finally ot_viewer_destroy(viewer); end; finally ot_shape_free(shape); end; finally occt_templot_shutdown; end; end; ``` -------------------------------- ### Runnable Example: Import, Inspect, Re-export (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Demonstrates importing a STEP file, checking its type, exporting it to STL, and cleaning up resources. ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef shape = ot_import_step("model.step"); if (!shape) { printf("import failed: %s\n", occt_templot_last_error()); occt_templot_shutdown(); return 1; } printf("shape type code: %d\n", ot_shape_type(shape)); if (!ot_export_stl(shape, "model.stl", 0.1)) printf("export failed: %s\n", occt_templot_last_error()); ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Dynamic Loading C Example (Unix) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Loads the SimpleOCCTVP library at runtime using dlopen and retrieves the initialization function. ```c // Unix (macOS / Linux) #include void *lib = dlopen("libsimpleOCCTVP.dylib", RTLD_NOW); // or .so void (*init)(void) = dlsym(lib, "occt_templot_init"); init(); // ... dlclose(lib); ``` -------------------------------- ### Dynamic Loading C Example (Windows) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Loads the SimpleOCCTVP library at runtime using LoadLibraryA and retrieves the initialization function. ```c // Windows #include HMODULE lib = LoadLibraryA("simpleOCCTVP.dll"); void (*init)(void) = (void(*)(void))GetProcAddress(lib, "occt_templot_init"); init(); // ... FreeLibrary(lib); ``` -------------------------------- ### Runnable example — extract and free a mesh Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A complete C code example demonstrating how to initialize the library, import a STEP model, extract its mesh data using `ot_mesh_shape`, print basic mesh information, free the mesh data using `ot_mesh_free`, free the shape, and shut down the library. ```APIDOC ## Runnable example — extract and free a mesh ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef shape = ot_import_step("model.step"); if (!shape) { occt_templot_shutdown(); return 1; } OTMeshData mesh = ot_mesh_shape(shape, 0.1); if (mesh.vertex_count > 0) { printf("vertices: %d triangles: %d\n", mesh.vertex_count, mesh.triangle_count); /* mesh.vertices is [x,y,z, nx,ny,nz, ...] — 6 floats per vertex */ float x = mesh.vertices[0], y = mesh.vertices[1], z = mesh.vertices[2]; printf("first vertex: %.3f %.3f %.3f\n", x, y, z); } ot_mesh_free(&mesh); /* always free; safe on a zeroed struct */ ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` ``` -------------------------------- ### Install Linux Dependencies Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Installs necessary development libraries on Debian-based Linux systems for building and running OpenGL-dependent applications. ```bash sudo apt-get install -y libgl-dev libglu1-mesa-dev libegl-dev libx11-dev libxi-dev libxmu-dev ``` -------------------------------- ### Pascal/Lazarus Example: Load, Mesh, and Free Shape Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Demonstrates initializing the library, importing a STEP file, extracting mesh data, and freeing resources in Pascal. ```pascal uses occt_templot; procedure LoadAndRender; var shape: OTShapeRef; mesh: OTMeshData; begin occt_templot_init; try shape := ot_import_step('model.step'); if shape = nil then raise Exception.Create('Import failed: ' + OTGetLastError); try mesh := ot_mesh_shape(shape, 0.1); try WriteLn('Triangles: ', mesh.triangle_count); finally ot_mesh_free(mesh); end; finally ot_shape_free(shape); end; finally occt_templot_shutdown; end; end; ``` -------------------------------- ### Main Program Entry with C API Usage Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A basic example demonstrating the initialization, version retrieval, error checking, and shutdown sequence of the simpleOCCTVP C API. ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); printf("simpleOCCTVP %s\n", occt_templot_version()); if (occt_templot_last_error()) printf("error: %s\n", occt_templot_last_error()); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Runnable Example: Analyze, Heal, and Measure Shape Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Demonstrates a typical workflow: importing a STEP file, analyzing its quality, healing it, measuring its volume and bounding box, and freeing the shape resources. Includes necessary initializations and shutdowns. ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef raw = ot_import_step("imperfect.step"); if (!raw) { occt_templot_shutdown(); return 1; } OTShapeAnalysis a = ot_analyze_shape(raw, 1e-6); printf("free edges: %d gaps: %d valid: %d\n", a.free_edge_count, a.gap_count, a.is_valid); OTShapeRef healed = ot_heal_shape(raw); if (healed) { double xmin, ymin, zmin, xmax, ymax, zmax; ot_shape_bounding_box(healed, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax); printf("volume: %.3f bbox: [%.1f..%.1f]\n", ot_shape_volume(healed), xmin, xmax); ot_shape_free(healed); } ot_shape_free(raw); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Runnable example: Extract and free a mesh Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Demonstrates the process of initializing the library, importing a STEP model, extracting its mesh data using `ot_mesh_shape`, printing vertex and triangle counts, accessing the first vertex's coordinates, and finally freeing the mesh data and shape. ```c #include "occt_templot.h" #include int main(void) { occt_templot_init(); OTShapeRef shape = ot_import_step("model.step"); if (!shape) { occt_templot_shutdown(); return 1; } OTMeshData mesh = ot_mesh_shape(shape, 0.1); if (mesh.vertex_count > 0) { printf("vertices: %d triangles: %d\n", mesh.vertex_count, mesh.triangle_count); float x = mesh.vertices[0], y = mesh.vertices[1], z = mesh.vertices[2]; printf("first vertex: %.3f %.3f %.3f\n", x, y, z); } ot_mesh_free(&mesh); ot_shape_free(shape); occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Get Library Version Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Retrieves the version string of the SimpleOCCTVP library. The format is typically 'major.minor.patch'. ```c occt_templot_version(); ``` -------------------------------- ### Viewer Lifecycle Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to create, destroy, resize, and get the dimensions of the offscreen viewer. ```APIDOC ## Viewer Lifecycle ### `ot_viewer_create` Creates a new offscreen viewer with the specified dimensions. **Parameters** - `width` (int32_t) - The width of the viewer. - `height` (int32_t) - The height of the viewer. **Returns** - `OTViewerRef` - A reference to the created viewer, or a null reference on failure. ### `ot_viewer_destroy` Destroys the offscreen viewer and releases associated resources. **Parameters** - `viewer` (OTViewerRef) - The viewer to destroy. ### `ot_viewer_resize` Resizes the offscreen viewer to the specified dimensions. **Parameters** - `viewer` (OTViewerRef) - The viewer to resize. - `width` (int32_t) - The new width of the viewer. - `height` (int32_t) - The new height of the viewer. **Returns** - `bool` - `true` if the resize was successful, `false` otherwise. ### `ot_viewer_get_size` Retrieves the current dimensions of the offscreen viewer. **Parameters** - `viewer` (OTViewerRef) - The viewer to query. - `out_width` (int32_t*) - Pointer to store the width. - `out_height` (int32_t*) - Pointer to store the height. ``` -------------------------------- ### Get simpleOCCTVP Library Version Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Retrieves the library version string. The returned pointer is owned by the library and should not be freed. ```c const char* occt_templot_version(void); ``` -------------------------------- ### Drawer Tessellation Quality Settings Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to set and get tessellation quality parameters for a drawer, including deviation coefficient, angle, and maximum deviation. ```c void ot_drawer_set_deviation_coefficient(OTDrawerRef drawer, double coeff); double ot_drawer_get_deviation_coefficient(OTDrawerRef drawer); void ot_drawer_set_deviation_angle(OTDrawerRef drawer, double radians); double ot_drawer_get_deviation_angle(OTDrawerRef drawer); void ot_drawer_set_max_deviation(OTDrawerRef drawer, double deviation); double ot_drawer_get_max_deviation(OTDrawerRef drawer); ``` -------------------------------- ### Two-phase mesh extraction with separate buffers Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A two-phase API for mesh extraction where the caller manages memory. First, get counts using `ot_mesh_shape_separate`, allocate memory for vertices, normals, and indices, then fill the buffers with `ot_mesh_shape_fill`. ```c bool ot_mesh_shape_separate(OTShapeRef shape, double deflection, int32_t* out_vertex_count, int32_t* out_triangle_count); bool ot_mesh_shape_fill(OTShapeRef shape, float* out_vertices, float* out_normals, int32_t* out_indices); ``` -------------------------------- ### Separate (caller-managed) buffers API Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md A two-phase API for callers who need to manage their own memory. First, call `ot_mesh_shape_separate` to get the vertex and triangle counts. Then, allocate memory for `out_vertices`, `out_normals` (as `float[vertex_count * 3]`), and `out_indices` (as `int32_t[triangle_count * 3]`). Finally, call `ot_mesh_shape_fill` to populate these allocated buffers. ```APIDOC ## Separate (caller-managed) buffers ### Description Two-phase API for callers that want to own the memory: first call `ot_mesh_shape_separate` to obtain counts, allocate `out_vertices`/`out_normals` as `float[vertex_count * 3]` and `out_indices` as `int32_t[triangle_count * 3]`, then call `ot_mesh_shape_fill` on the same shape. ### Function Signatures ```c bool ot_mesh_shape_separate(OTShapeRef shape, double deflection, int32_t* out_vertex_count, int32_t* out_triangle_count); bool ot_mesh_shape_fill(OTShapeRef shape, float* out_vertices, float* out_normals, int32_t* out_indices); ``` ``` -------------------------------- ### Build SimpleOCCTVP from Source Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Steps to clone the repository, build dependencies, and compile the library using CMake. ```bash git clone https://github.com/gsdali/simpleOCCTVP.git cd simpleOCCTVP scripts/build-occt-deps.sh # ~15-30 min, builds OCCT 8.0.0 cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build ``` -------------------------------- ### Get Shape Type (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Returns the type of the shape. Returns -1 for an error. ```c int32_t ot_shape_type(OTShapeRef shape); ``` -------------------------------- ### Initialize, Load, Mesh, Render, and Shutdown Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/guides/getting-started.md This C code demonstrates the core workflow: initializing the library, loading a STEP file, extracting a triangle mesh, rendering the shape to a PNG image, and finally shutting down the library. Ensure proper error checking after import operations and remember to free all allocated resources. ```c #include "occt_templot.h" #include int main(void) { /* 1. Initialize once at startup. */ occt_templot_init(); /* 2. Load a shape. Returns NULL on failure. */ OTShapeRef shape = ot_import_step("model.step"); if (!shape) { printf("import failed: %s\n", occt_templot_last_error()); occt_templot_shutdown(); return 1; } double xmin, ymin, zmin, xmax, ymax, zmax; ot_shape_bounding_box(shape, &xmin, &ymin, &zmin, &xmax, &ymax, &zmax); printf("bbox x: %.2f .. %.2f\n", xmin, xmax); /* 3. Extract a triangle mesh (interleaved position+normal). */ OTMeshData mesh = ot_mesh_shape(shape, 0.1); printf("triangles: %d vertices: %d\n", mesh.triangle_count, mesh.vertex_count); ot_mesh_free(&mesh); /* free the mesh buffers */ /* 4. Render the shape offscreen and save a PNG. */ OTViewerRef viewer = ot_viewer_create(800, 600); int32_t id = ot_viewer_add_shape(viewer, shape, OT_DISPLAY_SHADED); ot_viewer_set_shape_material(viewer, id, "steel"); ot_viewer_set_render_preset(viewer, OT_PRESET_BALANCED); ot_viewer_set_view_orientation(viewer, OT_VIEW_ISO); ot_viewer_fit_all(viewer); if (!ot_viewer_save_image(viewer, "render.png")) printf("render failed: %s\n", occt_templot_last_error()); ot_viewer_destroy(viewer); /* destroy the viewer */ /* 5. Free the shape and shut down. */ ot_shape_free(shape); /* the viewer does not own the shape */ occt_templot_shutdown(); return 0; } ``` -------------------------------- ### Camera Position and Orientation Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to set and get the eye position, look-at center, and up vector of the camera. ```APIDOC ## Camera Position and Orientation ### Description Manages the camera's position in the world, the point it is looking at, and its orientation. ### `ot_camera_set_eye` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double): The world coordinates of the camera's eye position. ### `ot_camera_get_eye` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double*): Pointers to store the camera's eye position coordinates. ### `ot_camera_set_center` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double): The world coordinates of the point the camera is looking at. ### `ot_camera_get_center` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double*): Pointers to store the look-at center coordinates. ### `ot_camera_set_up` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double): The components of the camera's up vector. ### `ot_camera_get_up` #### Parameters - `camera` (OTCameraRef): The camera object. - `x`, `y`, `z` (double*): Pointers to store the camera's up vector components. ``` -------------------------------- ### Get Last Error Message Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Retrieves the last error message associated with the current thread. Returns NULL if no error has occurred. ```c occt_templot_last_error(); ``` -------------------------------- ### Initialize the Library Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Initializes the SimpleOCCTVP library. This function should be called once at the beginning of your application's execution. ```c occt_templot_init(); ``` -------------------------------- ### Import STEP File (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports a STEP file. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_step(const char* path); ``` -------------------------------- ### Get Shape Bounding Box Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Retrieves the axis-aligned bounding box for a shape. Requires the shape handle and output parameters for the box coordinates. ```c ot_shape_bounding_box(shape, ...); ``` -------------------------------- ### CMake Integration: Adding from Source Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Configures CMake to add SimpleOCCTVP as a subdirectory, assuming it's built from source. ```cmake add_subdirectory(simpleOCCTVP) target_link_libraries(your_target PRIVATE simpleOCCTVP) ``` -------------------------------- ### Run Tests Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Executes the test suite after building the library. Use --output-on-failure for detailed test results. ```bash cd build && ctest --output-on-failure ``` -------------------------------- ### Import STEP Robustly (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports a STEP file with automatic healing and precision handling. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_step_robust(const char* path); ``` -------------------------------- ### Define OTEdgeMeshData structure Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Defines the structure for holding edge mesh data, including vertices, vertex count, segment start indices, and segment count. Vertices are stored as simple [x,y,z] coordinates. ```c typedef struct { float* vertices; int32_t vertex_count; int32_t* segment_starts; int32_t segment_count; } OTEdgeMeshData; ``` -------------------------------- ### Create Offscreen Viewer Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Creates an offscreen viewer instance with specified width and height. Returns a reference to the viewer. ```c ot_viewer_create(w, h); ``` -------------------------------- ### Import STEP with Diagnostics (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports a STEP file and reports on the repair steps applied. The returned shape must be freed. ```c typedef struct { OTShapeRef shape; int32_t original_type; int32_t result_type; bool sewing_applied; bool solid_created; bool healing_applied; } OTImportResult; OTImportResult ot_import_step_with_diagnostics(const char* path); ``` -------------------------------- ### Run Tests with xvfb on Linux Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Runs tests on headless Linux systems using xvfb to simulate a display environment for OpenGL tests. ```bash cd build && xvfb-run ctest --output-on-failure ``` -------------------------------- ### CMake Integration: Using Prebuilt Shared Library Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Configures CMake to find and use a prebuilt SimpleOCCTVP shared library, setting its location and include directories. ```cmake # Find the prebuilt shared library add_library(simpleOCCTVP SHARED IMPORTED) set_target_properties(simpleOCCTVP PROPERTIES IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/libs/libsimpleOCCTVP${CMAKE_SHARED_LIBRARY_SUFFIX}" INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/include" ) # On Windows, also set IMPORTED_IMPLIB to the .lib file target_link_libraries(your_target PRIVATE simpleOCCTVP) ``` -------------------------------- ### Import OBJ File (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports an OBJ file. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_obj(const char* path); ``` -------------------------------- ### Import STL Robustly (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports an STL file with a sew, solid, and heal pipeline. A sewing tolerance must be provided. ```c OTShapeRef ot_import_stl_robust(const char* path, double sewing_tolerance); ``` -------------------------------- ### Viewer Lifecycle Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to create, destroy, and resize the offscreen viewer. ```c OTViewerRef ot_viewer_create(int32_t width, int32_t height); void ot_viewer_destroy(OTViewerRef viewer); bool ot_viewer_resize(OTViewerRef viewer, int32_t width, int32_t height); void ot_viewer_get_size(OTViewerRef viewer, int32_t* out_width, int32_t* out_height); ``` -------------------------------- ### Build the Library with CMake Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Configures and builds the library using CMake. Specify the build type, e.g., Release. ```bash cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build ``` -------------------------------- ### Import STL File (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports an STL file. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_stl(const char* path); ``` -------------------------------- ### Compile C/C++ Application on Linux Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Command to compile a C application, linking against the SimpleOCCTVP library and specifying include and library paths with rpath. ```bash cc -o myapp myapp.c -I./include -L./libs -lsimpleOCCTVP -Wl,-rpath,'$ORIGIN/libs' ``` -------------------------------- ### Import with Diagnostics Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Import a STEP file and report diagnostic information about the repair process. ```APIDOC ## `ot_import_step_with_diagnostics` ### Description Import a STEP file and report which repair steps ran. The `shape` field is owned by the caller and must be freed with `ot_shape_free` when non-`NULL`. ### Result Structure ```c typedef struct { OTShapeRef shape; /* Result shape (NULL on failure) */ int32_t original_type; /* TopAbs_ShapeEnum before processing */ int32_t result_type; /* TopAbs_ShapeEnum after processing */ bool sewing_applied; /* Whether sewing was needed */ bool solid_created; /* Whether a solid was created from a shell */ bool healing_applied; /* Whether healing was applied */ } OTImportResult; ``` ### Signature ```c OTImportResult ot_import_step_with_diagnostics(const char* path); ``` ``` -------------------------------- ### Library Initialization and Shutdown Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to initialize the library before use and shut it down to release resources. ```APIDOC ## `occt_templot_init` ### Description Initialize the library. Call once before any other function. ### Signature ```c void occt_templot_init(void); ``` ``` ```APIDOC ## `occt_templot_shutdown` ### Description Shut down the library and release global resources. ### Signature ```c void occt_templot_shutdown(void); ``` ``` -------------------------------- ### Import IGES File (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports an IGES file. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_iges(const char* path); ``` -------------------------------- ### Import OBJ File Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Imports a shape from an OBJ file. The path to the OBJ file is required. ```c ot_import_obj(path); ``` -------------------------------- ### Build OCCT Dependencies Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Downloads and builds OCCT 8.0.0 as static libraries. Ensure you have CMake 3.20+ and a C++17 compiler. ```bash scripts/build-occt-deps.sh ``` -------------------------------- ### Render Scene to Buffer or File Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to render the scene. `ot_viewer_render` returns RGBA pixels bottom-to-top and the pointer is owned by the viewer. `ot_viewer_render_to_buffer` renders into a caller-allocated buffer top-to-bottom. `ot_viewer_save_image` renders and saves to a file. ```c const uint8_t* ot_viewer_render( OTViewerRef viewer, int32_t* out_width, int32_t* out_height, int32_t* out_size); bool ot_viewer_render_to_buffer(OTViewerRef viewer, uint8_t* buffer, int32_t buffer_size); bool ot_viewer_save_image(OTViewerRef viewer, const char* path); ``` -------------------------------- ### Compile C/C++ Application on macOS Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Command to compile a C application, linking against the SimpleOCCTVP library and specifying include and library paths. ```bash cc -o myapp myapp.c -I./include -L./libs -lsimpleOCCTVP -Wl,-rpath,@executable_path/libs ``` -------------------------------- ### Import STEP File Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Imports a shape from a STEP file. The path parameter specifies the file location. ```c ot_import_step(path); ``` -------------------------------- ### Set Viewer Background Gradient Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Sets a color gradient as the background for the viewer. Requires parameters defining the gradient. ```c ot_viewer_set_background_gradient(viewer, ...); ``` -------------------------------- ### Lifecycle Functions Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Functions for initializing, shutting down, and retrieving the version and last error of the library. ```APIDOC ## Lifecycle Functions ### Description Functions for initializing, shutting down, and retrieving the version and last error of the library. ### Functions - **occt_templot_init()** - Description: Initialize the library. Call once at startup. - **occt_templot_shutdown()** - Description: Release global resources. Call at exit. - **occt_templot_version()** - Description: Returns version string (e.g. "0.1.0"). - **occt_templot_last_error()** - Description: Thread-local error message, or `NULL`. ``` -------------------------------- ### Viewer Rendering Control Functions Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Provides C functions to configure various rendering parameters for the viewer, including presets, methods, path tracing, sampling, depth, shadows, reflections, antialiasing, tone mapping, depth of field, shading models, and environment cubemaps. ```c void ot_viewer_set_render_preset(OTViewerRef viewer, OTRenderPreset preset); void ot_viewer_set_rendering_method(OTViewerRef viewer, OTRenderingMethod method); void ot_viewer_set_path_tracing(OTViewerRef viewer, bool enabled); void ot_viewer_set_samples_per_pixel(OTViewerRef viewer, int32_t spp); void ot_viewer_set_ray_depth(OTViewerRef viewer, int32_t depth); void ot_viewer_set_shadows(OTViewerRef viewer, bool enabled, bool transparent_shadows); void ot_viewer_set_reflections(OTViewerRef viewer, bool enabled); void ot_viewer_set_antialiasing(OTViewerRef viewer, bool enabled); void ot_viewer_set_tone_mapping(OTViewerRef viewer, OTToneMappingMethod method, double exposure, double white_point); void ot_viewer_set_depth_of_field(OTViewerRef viewer, double aperture_radius, double focal_distance); void ot_viewer_set_shading_model(OTViewerRef viewer, OTShadingModel model); bool ot_viewer_set_environment_cubemap(OTViewerRef viewer, const char* image_path); void ot_viewer_clear_environment_cubemap(OTViewerRef viewer); void ot_viewer_set_environment_background(OTViewerRef viewer, bool enabled); ``` -------------------------------- ### Compile C/C++ Application on Windows (MSVC) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Command to compile a C application using MSVC, specifying include and library paths. ```bash cl /I include myapp.c /link /LIBPATH:libs simpleOCCTVP.lib ``` -------------------------------- ### Import STL File Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Imports a shape from an STL file. Returns an OTShapeRef handle to the imported shape. ```c ot_import_stl(path); ``` -------------------------------- ### Import IGES Robustly (C) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Imports an IGES file with automatic healing. Returns a new OTShapeRef or NULL on failure. ```c OTShapeRef ot_import_iges_robust(const char* path); ``` -------------------------------- ### ot_make_solid Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Attempts to create a solid shape from a given shell. Returns `NULL` if the operation is not possible. ```APIDOC ## ot_make_solid ### Description Create a solid from a shell. Returns `NULL` if not possible. ### Signature ```c OTShapeRef ot_make_solid(OTShapeRef shape); ``` ### Parameters - **shape** (OTShapeRef) - The shell shape to convert into a solid. ### Return Value A new `OTShapeRef` representing the solid shape, or `NULL` if it cannot be created. ``` -------------------------------- ### Compile and Link C Code (macOS) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/guides/getting-started.md Command to compile and link a C program on macOS, including necessary include and library paths, and setting the runtime search path for the shared library. ```bash # macOS cc -o myapp src/main.c -I include -L libs -lsimpleOCCTVP \ -Wl,-rpath,@executable_path/libs ``` -------------------------------- ### Drawer Creation and Destruction Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to create and destroy an OTDrawerRef. This drawer holds tessellation quality settings. ```c OTDrawerRef ot_drawer_create(void); void ot_drawer_destroy(OTDrawerRef drawer); ``` -------------------------------- ### Background Configuration Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to set the background color or gradient of the viewer. ```APIDOC ## Background Configuration ### `ot_viewer_set_background_color` Sets a solid background color for the viewer. **Parameters** - `viewer` (OTViewerRef) - The viewer to configure. - `r` (double) - Red component of the color (0.0 to 1.0). - `g` (double) - Green component of the color (0.0 to 1.0). - `b` (double) - Blue component of the color (0.0 to 1.0). ### `ot_viewer_set_background_gradient` Sets a two-color gradient background for the viewer. **Parameters** - `viewer` (OTViewerRef) - The viewer to configure. - `r1` (double) - Red component of the first color. - `g1` (double) - Green component of the first color. - `b1` (double) - Blue component of the first color. - `r2` (double) - Red component of the second color. - `g2` (double) - Green component of the second color. - `b2` (double) - Blue component of the second color. ``` -------------------------------- ### Shape Material and Emission Functions Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Allows setting physically based rendering (PBR) materials and emission properties for individual shapes within the viewer. ```c bool ot_viewer_set_shape_pbr_material(OTViewerRef viewer, int32_t display_id, double albedo_r, double albedo_g, double albedo_b, double metallic, double roughness); bool ot_viewer_set_shape_emission(OTViewerRef viewer, int32_t display_id, double r, double g, double b, double intensity); ``` -------------------------------- ### Export Shape to STEP Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Exports a shape to a STEP file. Provide the shape handle and the desired output file path. ```c ot_export_step(shape, path); ``` -------------------------------- ### Save Viewer Image Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Renders the viewer's content and saves it directly to an image file. Specify the output path for the image. ```c ot_viewer_save_image(viewer, path); ``` -------------------------------- ### Display Drawer Functions Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Functions for creating and configuring display drawers, used for custom tessellation settings. ```APIDOC ## Display Drawer ### `ot_drawer_create()` **Description**: Creates a new display drawer. **Returns**: `OTDrawerRef` - A reference to the newly created drawer. ### `ot_drawer_destroy(drawer)` **Description**: Destroys a display drawer and releases its resources. **Parameters**: - `drawer`: The `OTDrawerRef` of the drawer to destroy. ### `ot_drawer_set_deviation_coefficient(drawer, coeff)` **Description**: Sets the deviation coefficient for tessellation quality. **Parameters**: - `drawer`: The `OTDrawerRef` of the drawer. - `coeff` (float): The deviation coefficient. ### `ot_mesh_shape_with_drawer(shape, drawer)` **Description**: Meshes a shape using a display drawer with custom tessellation settings. **Parameters**: - `shape`: The shape to mesh. - `drawer`: The `OTDrawerRef` to use for tessellation. ``` -------------------------------- ### Import STEP with Healing Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Imports a STEP file and attempts to automatically heal any geometric issues. This is useful for repairing potentially problematic STEP files. ```c ot_import_step_robust(path); ``` -------------------------------- ### Make Solid Function Signature Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Attempts to create a solid shape from a given shell. Returns NULL if the operation is not possible. ```c OTShapeRef ot_make_solid(OTShapeRef shape); ``` -------------------------------- ### Compile and Link C Code (Windows MSVC) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/guides/getting-started.md Command to compile and link a C program on Windows using MSVC, specifying include and library paths. ```bash # Windows (MSVC) cl /I include src\main.c /link /LIBPATH:libs simpleOCCTVP.lib ``` -------------------------------- ### Camera Creation and Destruction Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to create and destroy standalone camera objects. ```APIDOC ## Camera Creation and Destruction ### Description Creates a new standalone camera object and destroys an existing one. ### `ot_camera_create` #### Returns - `OTCameraRef`: A reference to the newly created camera object. ### `ot_camera_destroy` #### Parameters - `camera` (OTCameraRef): The camera object to destroy. ``` -------------------------------- ### Lighting Configuration Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to control lighting, including headlights, directional lights, and ambient light. ```APIDOC ## Lighting Configuration ### `ot_viewer_set_headlight` Enables or disables the default headlight. **Parameters** - `viewer` (OTViewerRef) - The viewer to configure. - `enabled` (bool) - `true` to enable the headlight, `false` to disable. ### `ot_viewer_add_directional_light` Adds a directional light source to the scene. **Parameters** - `viewer` (OTViewerRef) - The viewer to add the light to. - `dir_x`, `dir_y`, `dir_z` (double) - The direction vector of the light. - `r`, `g`, `b` (double) - The color of the light (0.0 to 1.0). ### `ot_viewer_set_ambient_light` Sets the intensity of the ambient light. **Parameters** - `viewer` (OTViewerRef) - The viewer to configure. - `intensity` (double) - The ambient light intensity. ``` -------------------------------- ### Compile and Link C Code (Linux) Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/guides/getting-started.md Command to compile and link a C program on Linux, specifying include and library paths, and configuring the runtime path for the shared library. ```bash # Linux cc -o myapp src/main.c -I include -L libs -lsimpleOCCTVP \ -Wl,-rpath,'$ORIGIN/libs' ``` -------------------------------- ### Standalone Camera API Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Provides functions for creating, destroying, and configuring a standalone camera. Use these functions to manage camera state independently of any viewer. Matrices are column-major with zero-to-one depth. ```c OTCameraRef ot_camera_create(void); void ot_camera_destroy(OTCameraRef camera); void ot_camera_set_eye(OTCameraRef camera, double x, double y, double z); void ot_camera_get_eye(OTCameraRef camera, double* x, double* y, double* z); void ot_camera_set_center(OTCameraRef camera, double x, double y, double z); void ot_camera_get_center(OTCameraRef camera, double* x, double* y, double* z); void ot_camera_set_up(OTCameraRef camera, double x, double y, double z); void ot_camera_get_up(OTCameraRef camera, double* x, double* y, double* z); void ot_camera_set_projection_type(OTCameraRef camera, OTProjectionType type); OTProjectionType ot_camera_get_projection_type(OTCameraRef camera); void ot_camera_set_fov(OTCameraRef camera, double degrees); double ot_camera_get_fov(OTCameraRef camera); void ot_camera_set_scale(OTCameraRef camera, double scale); double ot_camera_get_scale(OTCameraRef camera); void ot_camera_set_z_range(OTCameraRef camera, double z_near, double z_far); void ot_camera_set_aspect(OTCameraRef camera, double aspect); bool ot_camera_get_projection_matrix(OTCameraRef camera, double* out16); bool ot_camera_get_view_matrix(OTCameraRef camera, double* out16); bool ot_camera_project(OTCameraRef camera, double world_x, double world_y, double world_z, double* out_x, double* out_y, double* out_z); bool ot_camera_unproject(OTCameraRef camera, double ndc_x, double ndc_y, double ndc_z, double* out_x, double* out_y, double* out_z); bool ot_camera_fit_bbox(OTCameraRef camera, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax); ``` -------------------------------- ### Import IGES File Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Imports a shape from an IGES file. Provide the file path as an argument. ```c ot_import_iges(path); ``` -------------------------------- ### Display Drawer Functions Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions for creating, destroying, and configuring display drawers. These drawers hold tessellation-quality settings for mesh extraction. ```APIDOC ## Display Drawer API ### Create Drawer ```c OTDrawerRef ot_drawer_create(void); ``` Creates a new display drawer. ### Destroy Drawer ```c void ot_drawer_destroy(OTDrawerRef drawer); ``` Destroys the specified display drawer. ### Set Deviation Coefficient ```c void ot_drawer_set_deviation_coefficient(OTDrawerRef drawer, double coeff); ``` Sets the deviation coefficient for the drawer. ### Get Deviation Coefficient ```c double ot_drawer_get_deviation_coefficient(OTDrawerRef drawer); ``` Gets the current deviation coefficient of the drawer. ### Set Deviation Angle ```c void ot_drawer_set_deviation_angle(OTDrawerRef drawer, double radians); ``` Sets the deviation angle in radians for the drawer. ### Get Deviation Angle ```c double ot_drawer_get_deviation_angle(OTDrawerRef drawer); ``` Gets the current deviation angle of the drawer. ### Set Max Deviation ```c void ot_drawer_set_max_deviation(OTDrawerRef drawer, double deviation); ``` Sets the maximum deviation allowed for the drawer. ### Get Max Deviation ```c double ot_drawer_get_max_deviation(OTDrawerRef drawer); ``` Gets the current maximum deviation of the drawer. ### Enable Face Boundary Draw ```c void ot_drawer_set_face_boundary_draw(OTDrawerRef drawer, bool enabled); ``` Enables or disables drawing of face boundaries. ### Get Face Boundary Draw Status ```c bool ot_drawer_get_face_boundary_draw(OTDrawerRef drawer); ``` Gets the current status of face boundary drawing. ### Mesh Shape with Drawer ```c OTMeshData ot_mesh_shape_with_drawer(OTShapeRef shape, OTDrawerRef drawer); ``` Generates mesh data for a shape using the specified drawer settings. The returned data is caller-owned and must be freed with `ot_mesh_free`. ### Edge Mesh Shape with Drawer ```c OTEdgeMeshData ot_edge_mesh_shape_with_drawer(OTShapeRef shape, OTDrawerRef drawer); ``` Generates edge mesh data for a shape using the specified drawer settings. The returned data is caller-owned and must be freed with `ot_edge_mesh_free`. ``` -------------------------------- ### Rendering Output Source: https://github.com/secondmouseau/simpleocctvp/blob/main/docs/reference/c-api.md Functions to render the scene to a buffer or save it as an image file. ```APIDOC ## Rendering Output ### `ot_viewer_render` Renders the scene and returns a pointer to the pixel data. **Parameters** - `viewer` (OTViewerRef) - The viewer to render. - `out_width` (int32_t*) - Pointer to store the width of the rendered image. - `out_height` (int32_t*) - Pointer to store the height of the rendered image. - `out_size` (int32_t*) - Pointer to store the size of the pixel data buffer in bytes. **Returns** - `const uint8_t*` - A pointer to the RGBA pixel data (bottom-to-top order). The pointer is owned by the viewer and is valid only until the next render call or viewer destruction. ### `ot_viewer_render_to_buffer` Renders the scene into a caller-provided buffer. **Parameters** - `viewer` (OTViewerRef) - The viewer to render. - `buffer` (uint8_t*) - The buffer to render the pixels into. - `buffer_size` (int32_t) - The size of the provided buffer in bytes. **Returns** - `bool` - `true` if rendering to the buffer was successful, `false` otherwise. The pixel data is in top-to-bottom order. ### `ot_viewer_save_image` Renders the scene and saves it to an image file. **Parameters** - `viewer` (OTViewerRef) - The viewer to render. - `path` (const char*) - The path to the output image file. The format is determined by the file extension (e.g., `.bmp`, `.png`). **Returns** - `bool` - `true` if the image was saved successfully, `false` otherwise. ``` -------------------------------- ### Set Viewer Background Color Source: https://github.com/secondmouseau/simpleocctvp/blob/main/README.md Sets a solid color as the background for the viewer. Specify the RGB color components (0.0 to 1.0). ```c ot_viewer_set_background_color(viewer, r, g, b); ```