TexGen
ShearedVoxelMesh.cpp
Go to the documentation of this file.
1/*=============================================================================
2TexGen: Geometric textile modeller.
3Copyright (C) 2010 Louise Brown
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18=============================================================================*/
19
20#include "PrecompiledHeaders.h"
21#include "ShearedVoxelMesh.h"
22#include "TexGen.h"
24#include <iterator>
25//#define SHINY_PROFILER TRUE
26
27
28using namespace TexGen;
29
30CShearedVoxelMesh::CShearedVoxelMesh(string Type)
31:CVoxelMesh(Type)
32{
33 //m_PeriodicBoundaries = new CShearedPeriodicBoundaries;
34}
35
37{
38 //delete m_PeriodicBoundaries;
39}
40
42{
43 XYZ DomSize;
44 double Angle1, Angle2;
45 CMesh Mesh = Textile.GetDomain()->GetMesh();
46
47 m_StartPoint = Mesh.GetNode(0);
48 XYZ Node4 = Mesh.GetNode(4);
49 XYZ Node2 = Mesh.GetNode(2);
50 DomSize.x = GetLength( m_StartPoint, Node4 );
51 DomSize.y = GetLength( m_StartPoint, Node2 );
52 DomSize.z = GetLength( m_StartPoint, Mesh.GetNode(1) );
53 Angle1 = atan2( Node4.y - m_StartPoint.y, Node4.x - m_StartPoint.x );
54 Angle2 = atan2( Node2.y - m_StartPoint.y, Node2.x - m_StartPoint.x );
55
56 m_ShearedVoxSize[0].x = DomSize.x * cos(Angle1) / m_XVoxels;
57 m_ShearedVoxSize[0].y = DomSize.x * sin(Angle1) / m_XVoxels;
58 m_ShearedVoxSize[1].x = DomSize.y * cos(Angle2) / m_YVoxels;
59 m_ShearedVoxSize[1].y = DomSize.y * sin(Angle2) / m_YVoxels;
60 m_ShearedVoxSize[2].x = m_ShearedVoxSize[2].y = DomSize.z / m_ZVoxels;
61 return true;
62}
63
64void CShearedVoxelMesh::OutputNodes(ostream &Output, CTextile &Textile, int Filetype )
65{
66 int x,y,z;
67 int iNodeIndex = 1;
68 vector<XYZ> CentrePoints;
69 vector<POINT_INFO> RowInfo;
70 XYZ StartPoint = m_StartPoint;
71
72 for ( z = 0; z <= m_ZVoxels; ++z )
73 {
74 StartPoint.x = m_StartPoint.x;
75 StartPoint.y = m_StartPoint.y;
76 StartPoint.z = m_StartPoint.z + m_ShearedVoxSize[2].x * z;
77 for ( y = 0; y <= m_YVoxels; ++y )
78 {
79 StartPoint.x = m_StartPoint.x + m_ShearedVoxSize[1].x * y;
80 StartPoint.y = m_StartPoint.y + m_ShearedVoxSize[1].y * y;
81 for ( x = 0; x <=m_XVoxels; ++x )
82 {
83 XYZ Point;
84 Point.x = StartPoint.x + m_ShearedVoxSize[0].x * x;
85 Point.y = StartPoint.y + m_ShearedVoxSize[0].y * x;
86 Point.z = StartPoint.z;
87
88 if (Filetype == INP_EXPORT)
89 {
90 Output << iNodeIndex << ", ";
91 Output << Point << "\n";
92 }
93 else if (Filetype == VTU_EXPORT)
94 m_Mesh.AddNode(Point);
95
96 if ( x < m_XVoxels && y < m_YVoxels && z < m_ZVoxels )
97 {
98 Point.x += 0.5*m_ShearedVoxSize[0].x;
99 Point.x += 0.5*m_ShearedVoxSize[1].x;
100 Point.y += 0.5*m_ShearedVoxSize[0].y;
101 Point.y += 0.5*m_ShearedVoxSize[1].y;
102 Point.z += 0.5*m_ShearedVoxSize[2].x;
103 CentrePoints.push_back(Point);
104 }
105 ++iNodeIndex;
106 }
107
108 }
109 RowInfo.clear(); // Changed to do layer at a time instead of row to optimise
110 Textile.GetPointInformation( CentrePoints, RowInfo );
111 m_ElementsInfo.insert(m_ElementsInfo.end(), RowInfo.begin(), RowInfo.end() );
112 CentrePoints.clear();
113 }
114}
const CMesh & GetMesh() const
Get the mesh representing the domain as a surface mesh.
Definition: Domain.h:73
Defines the nodes and elements of a surface or volume mesh.
Definition: Mesh.h:58
const int AddNode(XYZ Node)
Append a node to the list of nodes, the integer returns the index of the node
Definition: Mesh.cpp:2624
const XYZ & GetNode(int iIndex) const
Get the node with given ID.
Definition: Mesh.cpp:2636
bool CalculateVoxelSizes(CTextile &Textile)
Calculate voxel size based on number of voxels on each axis and domain size.
void OutputNodes(ostream &Output, CTextile &Textile, int Filetype=INP_EXPORT)
Outputs nodes to .inp file and gets element information.
Represents a textile cell containing yarns.
Definition: Textile.h:39
const CDomain * GetDomain() const
Definition: Textile.h:287
void GetPointInformation(const vector< XYZ > &Points, vector< POINT_INFO > &PointsInfo, double dTolerance=1e-9)
Get useful information of a list of points.
Definition: Textile.cpp:410
Class used to generate voxel mesh for output to ABAQUS.
Definition: VoxelMesh.h:35
int m_XVoxels
Number of voxels along x,y and z axes.
Definition: VoxelMesh.h:115
vector< POINT_INFO > m_ElementsInfo
Element information as calculated by GetPointInformation.
Definition: VoxelMesh.h:123
CMesh m_Mesh
Find intersections of yarn surfaces with grid of lines from node points in each axis.
Definition: VoxelMesh.h:112
Namespace containing a series of customised math operations not found in the standard c++ library.
@ INP_EXPORT
Definition: Misc.h:113
@ VTU_EXPORT
Definition: Misc.h:114
double GetLength(const XYZ &Point1, const XYZ &Point2)
Get the length between two points.
Definition: mymath.h:540
double x
Definition: mymath.h:104
double y
Definition: mymath.h:104
Struct for representing points in 3D space.
Definition: mymath.h:56
double z
Definition: mymath.h:57
double x
Definition: mymath.h:57
double y
Definition: mymath.h:57