PeriDyno 1.0.0
Loading...
Searching...
No Matches
FrameToPointSet.cu
Go to the documentation of this file.
1#pragma once
2#include "FrameToPointSet.h"
3#include "Topology/Frame.h"
4#include "Topology/PointSet.h"
5
6namespace dyno
7{
8 template<typename TDataType>
9 FrameToPointSet<TDataType>::FrameToPointSet()
10 : TopologyMapping()
11 {
12
13 }
14
15 template<typename TDataType>
16 FrameToPointSet<TDataType>::FrameToPointSet(std::shared_ptr<Frame<TDataType>> from, std::shared_ptr<PointSet<TDataType>> to)
17 : TopologyMapping()
18 {
19 m_from = from;
20 m_to = to;
21 }
22
23
24 template<typename TDataType>
25 FrameToPointSet<TDataType>::~FrameToPointSet()
26 {
27 if (m_refPoints.begin() != NULL)
28 {
29 m_refPoints.clear();
30 }
31 }
32
33
34 template<typename TDataType>
35 void FrameToPointSet<TDataType>::initialize(const Rigid& rigid, DArray<Coord>& points)
36 {
37 m_refRigid = rigid;
38 m_refPoints.resize(points.size());
39 m_refPoints.assign(points);
40 }
41
42
43 template<typename TDataType>
44 void FrameToPointSet<TDataType>::match(std::shared_ptr<Frame<TDataType>> from, std::shared_ptr<PointSet<TDataType>> to)
45 {
46 m_initFrom = std::make_shared<Frame<TDataType>>();
47 m_initTo = std::make_shared<PointSet<TDataType>>();
48
49 m_initFrom->copyFrom(*from);
50 m_initTo->copyFrom(*to);
51 }
52
53
54 template <typename Coord, typename Rigid, typename Matrix>
55 __global__ void ApplyRigidTranform(
56 DArray<Coord> points,
57 Coord curCenter,
58 Matrix curMat,
59 DArray<Coord> refPoints,
60 Coord refCenter,
61 Matrix refMat)
62 {
63 int pId = threadIdx.x + (blockIdx.x * blockDim.x);
64 if (pId >= points.size()) return;
65
66 points[pId] = curCenter + curMat*refMat.transpose()*(refPoints[pId] - refCenter);
67 }
68
69 template<typename TDataType>
70 void FrameToPointSet<TDataType>::applyTransform(const Rigid& rigid, DArray<Coord>& points)
71 {
72 if (points.size() != m_refPoints.size())
73 {
74 std::cout << "The array sizes does not match for RigidToPoints" << std::endl;
75 }
76
77 uint pDims = cudaGridSize(points.size(), BLOCK_SIZE);
78
79 ApplyRigidTranform<Coord, Rigid, Matrix><< <pDims, BLOCK_SIZE >> >(points, rigid.getCenter(), rigid.getRotationMatrix(), m_refPoints, m_refRigid.getCenter(), m_refRigid.getRotationMatrix());
80 }
81
82 template<typename TDataType>
83 bool FrameToPointSet<TDataType>::apply()
84 {
85 DArray<Coord>& m_coords = m_initTo->getPoints();
86
87 uint pDims = cudaGridSize(m_coords.size(), BLOCK_SIZE);
88
89 ApplyRigidTranform<Coord, Rigid, Matrix> << <pDims, BLOCK_SIZE >> >(
90 m_to->getPoints(),
91 m_from->getCenter(),
92 m_from->getOrientation(),
93 m_coords,
94 m_initFrom->getCenter(),
95 m_initFrom->getOrientation());
96
97 return true;
98 }
99
100
101 template<typename TDataType>
102 bool FrameToPointSet<TDataType>::initializeImpl()
103 {
104 match(m_from, m_to);
105 return true;
106 }
107
108 DEFINE_CLASS(FrameToPointSet);
109}