Development
Project Requirements
Functional Requirements
-
Load 3D Model:
- Read an STL file and load the model.
-
Scaling:
- Scale the model using either a multiplier or a target height while maintaining aspect ratios.
-
Slicing:
- Slice the model into layers of a specified thickness.
-
Reference Marks:
- Reference marks should be placed at the centroid of each slice, where appropriate.
- Reference marks should be inherited from adjacent slices where possible, including the shape of the mark.
- New reference marks should be a different shape when added to a slice where they are not inherited.
- New reference marks must be introduced to a layer that does have a reference mark inherited from an adjacent slice, to ensure there is continuity in the reassembly process.
- Ensure marks are aligned with adjacent slices.
- Marks must not overlap and must be inside the model's contours.
- Marks must not be placed on the contour's edges.
- Marks must not exceed the contour's boundaries.
- The distance between marks should be within the scale of the overall model.
- The size of the marks should be proportional to the model's scale, while maintaining visibility.
- The marks need to be able to be used to properly align the slices during reassembly, including rotational alignment in addition to translational alignment.
-
SVG Generation:
- Generate an SVG file for each slice.
- Include contours, reference marks, and slice numbers.
- Each slice should be labeled with its number within the contour area.
Non-Functional Requirements
- The application should bundle all dependencies to mimic a statically compiled binary.
- The executable should run on different platforms without requiring a Python installation.
Pseudocode
- Load the 3D Model:
- Read an STL file to load the model into the application.
- Scale the Model:
- If a scale factor is provided, scale the model by this factor.
- If a target height is provided, calculate the necessary scale factor to achieve this height and apply it to the model, ensuring the aspect ratios are maintained.
- Calculate the Model Origin:
- Determine the model's origin point for reference in subsequent operations.
- Slice the Model into Layers:
- Determine the positions for each slice based on the specified layer height.
- For each determined position:
- Slice the model at this position.
- Project the resulting slice to a 2D plane.
- Create a List of
Polygon
s representing the 2D contours of the slice.
- For each slice, process the slice:
- Calculate Reference Marks:
- Retrieve potential reference marks based on the centroids of the slice's contours.
- Use the ReferenceMarkManager to find the closest existing mark within a tolerance or create a new mark if none is sufficiently close, ensuring:
- Marks are inherited from adjacent slices where possible.
- New marks are assigned a unique shape if not inherited.
- Marks do not overlap and are contained within the model's contours.
- Marks are not placed on the model's edges.
- The distance between marks is appropriate for the model's scale.
- The size of the marks is proportional to the model's scale, ensuring visibility.
- Adjust Reference Marks:
- Adjust the positions of the reference marks to avoid overlaps, using the ReferenceMarkAdjuster.
- Generate SVG File:
- Draw the slice contours.
- Add the adjusted reference marks.
- Annotate the slice with its number within the contour area.
- Calculate Reference Marks:
- Output:
- Save the generated SVG files to the specified output directory, with each file representing a slice of the original 3D model.