Skip to content

Commit

Permalink
2-Oct-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Oct 2, 2024
1 parent e1a5f92 commit 1e1f662
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 2 deletions.
158 changes: 158 additions & 0 deletions cpp/SampleCommands/SampleFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#pragma once

/// <summary>
/// Evaluate torsion of a curve at a parmeter.
/// </summary>
/// <param name="curve">Curve to evaluate.</param>
/// <param name="t">Evaluation parameter.</param>
/// <returns>The torsion if successful.</returns>
/// <remarks>See Barrett O'Neill, Elementary Differential Geometry, page 69.</remarks>
double ON_CurveTorsion(const ON_Curve& curve, double t);

/// <summary>
/// Create a blend curve with G0 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG0Curve(
const ON_Curve* crvA,
const ON_Curve* crvB
);

/// <summary>
/// Create a blend curve with G1 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <param name="bulgeA">Bulge factor at curveA end of blend. Values near 1.0 work best.</param>
/// <param name="bulgeB">Bulge factor at curveB end of blend. Values near 1.0 work best.</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG1Curve(
const ON_Curve* crvA,
const ON_Curve* crvB,
double bulgeA,
double bulgeB
);

/// <summary>
/// Create a blend curve with G2 continuity between two existing curves.
/// </summary>
/// <param name="crvA">Curve to blend from (blending will occur at curve end point).</param>
/// <param name="crvB">Curve to blend to (blending will occur at curve start point).</param>
/// <param name="bulgeA">Bulge factor at curveA end of blend. Values near 1.0 work best.</param>
/// <param name="bulgeB">Bulge factor at curveB end of blend. Values near 1.0 work best.</param>
/// <returns>An ON_Curve representing the blend between A and B.</returns>
/// <remarks>
/// CRITICAL: Memory for the resulting curve is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Curve* ON_BlendG2Curve(
const ON_Curve* crvA,
const ON_Curve* crvB,
double bulgeA,
double bulgeB
);

/// <summary>
/// Get the BRep definition of a trimmed surface.
/// </summary>
/// <param name="srf">Surface that will be trimmed.</param>
/// <param name="crv2d">
/// Closed, 2d parameter space boundary curve that defines the
/// outer boundary of the trimmed surface.
/// </param>
/// <param name="tol">Tolerance for fitting 3d edge curves.</param>
/// <returns>
/// An ON_Brep representation of the trimmed surface with a single face.
/// </returns>
/// <remarks>
/// CRITICAL: Memory for the resulting BRep is allocated. It is the calling
/// functions responsibility to clean up the memory.
/// </remarks>
ON_Brep* ON_BrepFromSurfaceAndBoundary(
const ON_Surface& srf,
const ON_Curve& crv2d,
double tol
);

/// <summary>
/// Returns the bitmap preview image from a 3dm file.
/// </summary>
/// <param name="pszFilePath">The full path to the 3dm file.</param>
/// <returns>An HBITMAP if successful, or nullptr if the 3dm file does not
/// contain a preview image or if there was an error reading the file.
/// </returns>
/// <remarks>
/// CRITICAL: Memory for the bitmap is allocated. It is the calling
/// functions responsibility to clean up the memory by calling the
/// Win32 DeleteObject() function.
/// </remarks>
HBITMAP ON_ReadBitmapPreviewImage(const wchar_t* pszFilePath);

/// <summary>
/// CRhinoHatchPatternTable helpers for system hatch patterns
/// </summary>
class CRhinoHatchTableHelper
{
public:
/// <summary>
/// Returns the Solid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Solid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch1 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch1(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch2 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch2(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Hatch3 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Hatch3(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the HatchDash hatch pattern
/// </summary>
static const CRhinoHatchPattern* HatchDash(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Grid60 hatch pattern
/// </summary>
static const CRhinoHatchPattern* Grid60(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Plus hatch pattern
/// </summary>
static const CRhinoHatchPattern* Plus(CRhinoHatchPatternTable& table);
/// <summary>
/// Returns the Squares hatch pattern
/// </summary>
static const CRhinoHatchPattern* Squares(CRhinoHatchPatternTable& table);

private:
static const CRhinoHatchPattern* FindOrCreateHatchPattern(CRhinoHatchPatternTable& table, const ON_HatchPattern& hatch_pattern);
};


/// <summary>
/// Returns true if Rhino was started as a standalone executable.
/// Returns false if Rhino was started by some other application or process.
/// </summary>
bool IsRhinoRunningAsExe();

/// <summary>
/// Returns true if Rhino has input focus.
/// </summary>
bool RhinoHasFocus();
13 changes: 11 additions & 2 deletions cpp/SampleCommands/cmdSampleAddNurbsCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ CRhinoCommand::result CCommandSampleAddNurbsCircle::RunCommand(const CRhinoComma
if (nullptr == doc)
return CRhinoCommand::failure;

// Specify dimension, degree and number of control points.
// The degree must be >= 1 and the number of control points
// must be >= (degree+1). The number of knots is always
// (number of control points + degree - 1).
int dimension = 3;
BOOL bIsRational = TRUE;
int order = 3; // order = degree + 1
bool bIsRational = true;
int degree = 2;
int order = degree + 1;
int cv_count = 9;
int knot_count = cv_count + degree - 1;

// Make a rational, degree 2 NURBS curve with 9 control points
ON_NurbsCurve nc(dimension, bIsRational, order, cv_count);
// Set the control points
nc.SetCV(0, ON_4dPoint(1.0, 0.0, 0.0, 1.0));
nc.SetCV(1, ON_4dPoint(0.707107, 0.707107, 0.0, 0.707107));
nc.SetCV(2, ON_4dPoint(0.0, 1.0, 0.0, 1.0));
Expand All @@ -48,6 +56,7 @@ CRhinoCommand::result CCommandSampleAddNurbsCircle::RunCommand(const CRhinoComma
nc.SetCV(6, ON_4dPoint(0.0, -1.0, 0.0, 1.0));
nc.SetCV(7, ON_4dPoint(0.707107, -0.707107, 0.0, 0.707107));
nc.SetCV(8, ON_4dPoint(1.0, 0.0, 0.0, 1.0));
// Set the 10 knots
nc.SetKnot(0, 0.0);
nc.SetKnot(1, 0.0);
nc.SetKnot(2, 0.5*ON_PI);
Expand Down
Loading

0 comments on commit 1e1f662

Please sign in to comment.