Cogs.Core
TrajectoryAlignedComponent.cpp
1#include "TrajectoryAlignedComponent.h"
2
3#include "Components/Core/TransformComponent.h"
4#include "Components/Data/TrajectoryComponent.h"
5
6#include "Utilities/Math.h"
7
8#include "Types.h"
9
10#include "Foundation/Geometry/BoundingBox.hpp"
11#include "Foundation/Geometry/SampleListGenerator.hpp"
12#include "Foundation/Geometry/PathGenerator.hpp"
13
14#include <algorithm>
15
16using namespace Cogs::Reflection;
17using namespace Cogs::Geometry;
18
19void Cogs::Core::TrajectoryAlignedComponent::registerType()
20{
21 Field fields [] = {
25 };
26
27 Method methods [] = {
29 };
30
31 DynamicComponent::registerDerivedType<TrajectoryAlignedComponent>().setFields(fields).setMethods(methods);
32}
33
35{
36 if (!trajectory) return;
37
38 const TrajectoryComponent* trajectoryComponent = trajectory->getComponent<TrajectoryComponent>();
39
40 if (!trajectoryComponent) return;
41
42 std::vector<float> depths;
43
44 SampleListGenerator::generateIndexedSamples(
45 depth,
46 depth + 1.0f,
47 trajectoryComponent->indexes.data(),
48 static_cast<int>(trajectoryComponent->indexes.size()),
49 depths);
50
51 if (!depths.size()) return;
52
53 // We only need one depth, but two is the minimum for generating path/direction info.
54 depths.resize(2);
55
56 glm::vec3 position[2];
57 glm::vec3 direction[2];
58
59 PathGenerator::generateLinearPath(depths.data(),
60 static_cast<int>(depths.size()),
61 trajectoryComponent->indexes.data(),
62 trajectoryComponent->positions.data(),
63 static_cast<int>(trajectoryComponent->indexes.size()),
64 position,
65 direction);
66
67 TransformComponent* transformComponent = getComponent<TransformComponent>();
68
69 glm::vec3 newPosition = position[0] + offset;
70 glm::quat newRotation = getRotation(glm::vec3(0, 0, -1), direction[0]) * rotation;
71 if (transformComponent->position != newPosition || transformComponent->rotation != newRotation) {
72 transformComponent->position = newPosition;
73 transformComponent->rotation = newRotation;
74 transformComponent->setChanged();
75 }
76}
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
Definition: Component.h:202
ComponentType * getComponent() const
Definition: Component.h:159
float depth
The depth along the trajectory to position the shape at.
glm::quat rotation
Rotation around the objects local axes.
std::shared_ptr< ComponentModel::Entity > trajectory
Target trajectory along which to align.
Defines a 4x4 transformation matrix for the entity and a global offset for root entities.
glm::quat rotation
Rotation given as a quaternion.
glm::vec3 position
Local position relative to the global coordinates, or the parent coordinate system if the parent fiel...
Field definition describing a single data member of a data structure.
Definition: Field.h:68
Simple method definition.
Definition: Method.h:72
Contains geometry calculations and generation.
Contains reflection support.
Definition: Component.h:11
Data component defining a 3D trajectory, for example a Well trajectory.
std::vector< float > indexes
Positive distances along trajectory. For wells Measured Depth (MD). Set same length of indexes and po...
std::vector< glm::vec3 > positions
Trajectory positions. For wells the Z component is a measurement of True Vertical Depth (TVD)....
Represents an unique name.
Definition: Name.h:70