This example demonstrates displaying and modifying the properties of the ray object. This example uses a console menu that represents the following operations: getting and setting the base point [B] and direction vector [D]; computing the features at a parameter [Z]; displaying the object properties, general properties, computed properties, and specific properties [P]; and modifying the general entity properties [M].
The PrintRayProperties() function requires a pointer to an existing ray object and displays its specific properties. The function gets the specific properties using the basePoint() and unitDir() methods. The function uses the AboutPoint3d() function for converting the coordinates of the base point to a string value and the AboutVector3d() function for converting the coordinates of the direction vector to a string value. The AboutPoint3d() and AboutVector3d() functions require an instance of the three-dimensional point or three-dimensional vector to be converted as an argument and return a string containing the X,Y,Z coordinates.
The PrintRayProperties() function has the following implementation:
void PrintRayProperties(OdDbRay* pRay)
{
wcout << L"\n Direction = " << AboutVector3d(pRay->unitDir())
<< L"\n Base point = " << AboutPoint3d(pRay->basePoint());
}
The PrintRayFeatures() function requires a pointer to an existing ray object and displays the properties computed at a parameter (features). The function uses the getStartPoint(), getStartParam(), getPointAtParam(), getFirstDeriv(), getSecondDeriv(), and getPlane() methods, and also uses the AboutPoint3d() and AboutVector3d() functions. The parameter is the distance measured from the base point. The ray does not have a length, area, end parameter, or end point. The first and second derivatives are vectors which are computed at a parameter and are constant for any point on the ray. A ray is an entity that has an arbitrary plane passed through it. The function gets and displays the coefficients of the arbitrary plane using the AboutPlane() function.
The PrintRayFeatures() function has the following implementation:
void PrintRayFeatures(OdDbRay* pRay)
{
OdGePlane plane;
OdGePoint3d point;
OdGeVector3d vector;
OdDb::Planarity planarity;
double value;
pRay->getStartPoint(point);
wcout << L"\n Start point = " << AboutPoint3d(point);
pRay->getStartParam(value);
wcout << L"\n Start parameter = " << value;
pRay->getFirstDeriv(0, vector);
wcout << L"\n First derivative = " << AboutVector3d(vector);
pRay->getSecondDeriv(0, vector);
wcout << L"\n Second derivative = " << AboutVector3d(vector);
if(pRay->getPlane(plane, planarity) == eOk)
wcout << L"\n " << ((planarity == OdDb::kPlanar) ? L"Entity" :
(planarity == OdDb::kLinear) ? L"Arbitrary" : L"Non")
<< L" Plane = " << AboutPlane(plane);
}
The ModifyRayProperties() function requires a pointer to an existing ray object and implements the console menu for the listed operations. The function organizes a loop that inquires about the operation code and uses the switch statement to select whether the case must be performed. The function processes user actions in the loop until the user selects the [Q] operation. The function uses the EntryPoint3d() function for entering coordinates of a three-dimensional point and the EntryVector3d() function for entering coordinates of a three-dimensional vector. The EntryPoint3d() and EntryVector3d() functions require a reference to an instance of the three-dimensional point or three-dimensional vector to be modified as an argument and return True when the passed instance is modified successfully or False when the user cancels entry.
When the user selects [P], the function displays the common object properties using the PrintObjectProperties() function, general entity properties using the PrintEntityProperties() function, computed ray properties using the PrintRayFeatures() function, and specific ray properties using the PrintRayProperties() function. When the user selects the [p] operation, the function displays only specific ray properties.
When the user selects [B], the function gets the base point using the basePoint() method, calls the EntryPoint3d() function for entry of its coordinates, and sets the returned point as the new base point using the setBasePoint() method if entry is successful.
When the user selects [D], the function gets the direction vector using the unitDir() method, calls the EntryVector3d() function for entry of its coordinates, and sets the returned vector as a new direction using the setUnitDir() method if entry is successful.
When the user selects [Z], the function requests a parameter as a double value. If an entered value is correct, the function computes the coordinates of the point on the ray corresponding to the specified parameter using the getPointAtParam() method, computes the distance from the start point to the computed point using the getDistAtParam() method, and computes the first and second derivatives in the computed point using the getFirstDeriv() and getSecondDeriv() methods.
When the user selects [M], the function calls the ModifyEntityProperties() function and passes to it the pointer to the ray object for modifying its general entity properties. After modification, the function displays all ray properties using the [P] operation.
When the user selects [Q], the function ends the loop and returns in the calling function.
The ModifyRayProperties() function has the following implementation:
#include "..\Common\DemoMain.h"
#include "DbRay.h"
#include <iostream>
using namespace std;
OdString AboutPoint3d(const OdGePoint3d& point);
bool EntryPoint3d(OdGePoint3d& point);
OdString AboutVector3d(const OdGeVector3d& vector);
bool EntryVector3d(OdGeVector3d& vector);
void PrintEntityProperties(OdDbEntity *pEntity);
void ModifyEntityProperties(OdDbEntity *pEntity);
void ModifyRayProperties(OdDbRay* pRay)
{
wchar_t ch = L'\0';
double value, param;
OdGePoint3d point;
OdGeVector3d vector;
wcout << L"\n\nStart modifying of the ray properties";
do {
switch(ch)
{
case L'M': // Modify the general properties
case L'm':
ModifyEntityProperties(pRay);
case L'P': // Print the whole properties
wcout << L"\nH=" << pRay->handle().ascii();
wcout << L"\n ------ Common Object Properties";
PrintObjectProperties(pRay);
wcout << L"\n ------ General Entity Properties";
PrintEntityProperties(pRay);
wcout << L"\n ------ Computed Ray Properties";
PrintRayFeatures(pRay);
case L'p': // Print the specific properties
wcout << L"\n ------ Specific Ray Properties";
PrintRayProperties(pRay);
wcout << L"\n";
break;
case L'D': // Set the direction
case L'd':
wcout << L"Entry the direction";
vector = pRay->unitDir();
if(EntryVector3d(vector))
{
pRay->setUnitDir(vector);
wcout << L"Direction is set to " << AboutVector3d(pRay->unitDir()) << L"\n";
}
break;
case L'B': // Set the base point
case L'b':
wcout << L"Entry the base point";
point = pRay->basePoint();
if(EntryPoint3d(point))
{
pRay->setBasePoint(point);
wcout << L"Base point is set to " << AboutPoint3d(pRay->basePoint()) << L"\n";
}
break;
case L'Z': // Compute the features at parameter
case L'z':
wcout << L"\nEntry a parameter:>";
wcin >> param;
if(!wcin.fail() && wcin.peek() == 10)
{
wcout << L"Compute at (" << param << L"):";
if(pRay->getDistAtParam(param, value) == eOk)
wcout << L"\nDistance = " << value;
if(pRay->getPointAtParam(param, point) == eOk)
wcout << L"\nPoint on = " << AboutPoint3d(point);
if(pRay->getFirstDeriv(param, vector) == eOk)
wcout << L"\n1-Derivative = " << AboutVector3d(vector);
if(pRay->getSecondDeriv(param, vector) == eOk)
wcout << L"\n2-Derivative = " << AboutVector3d(vector);
wcout << L"\n--at--";
}
else { wcin.clear(); wcin.sync(); wcout << L"Error: Invalid entered value\n"; }
break;
case L'\0': // Skip an action
break;
default:
wcout << L"Error: Incorrect operation\n";
}
wcout << L"\nD. Set the direction";
wcout << L"\nB. Set the base point";
wcout << L"\nP. Print the whole properties";
wcout << L"\np. Print the specific properties";
wcout << L"\nM. Modify the general properties";
wcout << L"\nZ. Compute the features at parameter";
wcout << L"\nQ. Quit";
wcout << L"\nSelect operation:>";
wcin >> ch;
}
while(ch != L'Q' && ch != L'q');
wcout << L"Stop modifying of the ray properties\n";
}
Testing gives the following results:
Start modifying of the ray properties
D. Set the direction
B. Set the base point
P. Print the whole properties
p. Print the specific properties
M. Modify the general properties
Z. Compute the features at parameter
Q. Quit
Select operation:>
When the operation is p-"Print the specific properties":
------ Specific Ray Properties
Direction = (0,0,1)
Base point = (0,0,0)
When the operation is B-"Set the base point":
Entry the base point
Current coordinates: (0,0,0)
Entry X-coordinate:>2.1
Entry Y-coordinate:>4.5
Entry Z-coordinate:>3.8
Base point is set to (2.1,4.5,3.8)
When the operation is D-"Set the direction":
Entry the direction
Current vector directions: (0,0,1)
Entry X-direction:>0.8
Entry Y-direction:>1.4
Entry Z-direction:>0.2
Direction is set to (0.492366, 0.86164, 0.123091)
When the operation is Z-"Compute the features at parameter":
Entry a parameter:>4.5
Compute at (4.5):
Distance = 4.5
Point on = (4.31565,8.37738,4.35391)
1-Derivative = (0.492366,0.86164,0.123091)
2-Derivative = (0,0,0)
--at--
Entry a parameter:>100
Compute at (100):
Distance = 100
Point on = (51.3366,90.664,16.1091)
1-Derivative = (0.492366,0.86164,0.123091)
2-Derivative = (0,0,0)
--at--
Entry a parameter:>-32 // error for point
Compute at (-32):
Distance = 32
1-Derivative = (0.492366,0.86164,0.123091)
2-Derivative = (0,0,0)
--at--
When the operation is P-"Print all properties":
H=40
------ Common Object Properties
Type: AcDbRay
Status: unerased,resident,modified,forRead,forWrite
Database: c:\test.dwg
------ General Entity Properties
Block: [1F-"*Model_Space"-Block]
Layer: [10-"0"-Layer]
Material: [3C-"ByLayer"-Material]
Linetype: [15-"ByLayer"-Linetype]
Lineweight: [kLnWtByLayer]
Transparency: [byLayer]
Visual style: [Db:kNull]
PlotStyleName: ByLayer
Linetype scale: 1
Color: [byLayer], Index = 256
State: Planar, Visible, Cast Shadows, Receive Shadows
------ Computed Ray Properties
Start point = (2.1,4.5,3.8)
Start parameter = 0
First derivative = (0.492366,0.86164,0.123091)
Second derivative = (0,0,0)
Arbitrary Plane = (-0.868243 * X + 0.496139 * Y + 0 * Z + -0.409315)
------ Specific Ray Properties
Direction = (0.492366,0.86164,0.123091)
Base point = (2.1,4.5,3.8)
Use the Q-"Quit" operation to exit:
Stop modifying of the ray properties
Example of Working with the Xline Object
Example of Entering and Displaying 3D Point Objects
Example of Entering and Displaying 3D Vector Objects
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|