0% found this document useful (0 votes)
145 views8 pages

Code 2

The document describes code for simulating a spring data structure. It defines constants for the width, height, and granularity of the structure. The Springdatastructure class initializes the structure with the given dimensions, sets up a mesh to store point data, and defines functions for linking points, calculating forces, and visualizing the structure as spheres. The StructureVisualisation class creates spheres for each point and updates their positions based on the spring data structure.

Uploaded by

Sens3nmann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views8 pages

Code 2

The document describes code for simulating a spring data structure. It defines constants for the width, height, and granularity of the structure. The Springdatastructure class initializes the structure with the given dimensions, sets up a mesh to store point data, and defines functions for linking points, calculating forces, and visualizing the structure as spheres. The StructureVisualisation class creates spheres for each point and updates their positions based on the spring data structure.

Uploaded by

Sens3nmann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Springdatastructure.cpp - !!! DRAFT !!!

#define defWIDTH 10.0f


#define defHEIGHT 10.0f
#define defGRANULARITY 1
Springdatastructure::Springdatastructure()
{
Springdatastructure(defWIDTH, defHEIGHT, defGRANULARITY);

//Logging
m_logging.resize(100);
m_logging[0] = "Standard constructor invoked";

Springdatastructure::~Springdatastructure()
{
}
Springdatastructure::Springdatastructure(double width = -1, double height = -1, int granularity = -1)
{
if (width < 0)
{
m_width = defWIDTH;
}
else {
m_width = width;
}
if (height < 0)
{
m_height = defHEIGHT;
}
else {
m_height = height;
}
if (granularity <= 0)
{
m_granularity = defGRANULARITY;
}
else {
m_granularity = granularity;
}

for (int i = 0; i < m_width * m_granularity; i++)


{
m_dataMesh[i].resize(m_height * m_granularity);
}
setCoordinates();

void Springdatastructure::init(linktype ltype, calculationtype ctype)


{
m_linktype = ltype;
m_calculationtype = ctype;
}

void Springdatastructure::setCoordinates(void)
{
double dWidthrange = m_width * m_granularity;
double dHeightrange = m_height * m_granularity;
int iVectorsize = 0;
if (m_linktype == SIMPLETYPE)
{
iVectorsize = 4;
} else
{
iVectorsize = 8;
}

for (int i = 0; i < m_dataMesh.size(); i++)


{
for (int j = 0; j < m_dataMesh[0].size(); j++)
{
m_dataMesh[i][j].vpNeighbours.resize(iVectorsize);
m_dataMesh[i][j].gridpoint = CHVector(i / dWidthrange, j / dHeightrange, 0.0);
}
}

void Springdatastructure::setLinkType(linktype type)


{
m_linktype = type;
}
void Springdatastructure::setCalculationType(calculationtype type)
{
m_calculationtype = type;
}
void Springdatastructure::linkDataPoints(void)
{
if ((m_width * m_granularity >= 3) || (m_height * m_granularity >= 3))
{
if (m_linktype == SIMPLETYPE)
{
linkDataPointsSimple();
}
else if (m_linktype == EXTENDEDTYPE)
{
linkDataPointsExtended();
}
}
}
void Springdatastructure::linkDataPointsExtended(void)
{
//Inner Rectangle
int meshwidth = m_dataMesh.size();
int meshheight = m_dataMesh[0].size();
Pointdata* p_pointdata;
Pointdata* p_cornerpoints;

for (int i = 0; i < meshwidth - 1; i++)


{
for (int j = 0; j < meshheight - 1; j++)
{
p_pointdata = &m_dataMesh[i][j];
// Top Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[i - 1][j - 1];
p_pointdata->vpNeighbours[1] = &m_dataMesh[i][j - 1];
p_pointdata->vpNeighbours[2] = &m_dataMesh[i + 1][j - 1];
// Mid Row
p_pointdata->vpNeighbours[3] = &m_dataMesh[i - 1][j];
p_pointdata->vpNeighbours[4] = &m_dataMesh[i + 1][j];
// Bottom Row
p_pointdata->vpNeighbours[5] = &m_dataMesh[i - 1][j + 1];
p_pointdata->vpNeighbours[6] = &m_dataMesh[i][j + 1];
p_pointdata->vpNeighbours[7] = &m_dataMesh[i + 1][j + 1];
}

// Top Lane
for (int i = 1; i < meshwidth - 1; i++)
{
p_pointdata = &m_dataMesh[i][0];
// Mid Row
p_pointdata->vpNeighbours[3] = &m_dataMesh[i - 1][0];
p_pointdata->vpNeighbours[4] = &m_dataMesh[i + 1][0];
// Bottom Row
p_pointdata->vpNeighbours[5] = &m_dataMesh[i - 1][1];
p_pointdata->vpNeighbours[6] = &m_dataMesh[i][1];
p_pointdata->vpNeighbours[7] = &m_dataMesh[i + 1][1];
}
// Bottom Lane
for (int i = 1; i < meshwidth - 1; i++)
{
p_pointdata = &m_dataMesh[i][meshheight-1];
// Top Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[i - 1][meshheight - 2];
p_pointdata->vpNeighbours[1] = &m_dataMesh[i][meshheight - 2];
p_pointdata->vpNeighbours[2] = &m_dataMesh[i + 1][meshheight - 2];

// Mid Row
p_pointdata->vpNeighbours[3] = &m_dataMesh[i - 1][meshheight - 1];
p_pointdata->vpNeighbours[4] = &m_dataMesh[i + 1][meshheight - 1];

// Left Lane
for (int j = 1; j < meshheight- 1; j++)
{
p_pointdata = &m_dataMesh[0][j];
// Right Row
p_pointdata->vpNeighbours[2] = &m_dataMesh[1][j - 1];
p_pointdata->vpNeighbours[4] = &m_dataMesh[1][j];
p_pointdata->vpNeighbours[7] = &m_dataMesh[1][j + 1];

// Mid Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[0][j - 1];
p_pointdata->vpNeighbours[6] = &m_dataMesh[0][j + 1];

// Right Lane
for (int j = 1; j < meshheight - 1; j++)
{
p_pointdata = &m_dataMesh[meshwidth - 1][j];
// Left Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[meshwidth - 2][j - 1];
p_pointdata->vpNeighbours[1] = &m_dataMesh[meshwidth - 2][j];
p_pointdata->vpNeighbours[5] = &m_dataMesh[meshwidth - 2][j + 1];
// Mid Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[meshwidth - 1][j - 1];
p_pointdata->vpNeighbours[6] = &m_dataMesh[meshwidth - 1][j + 1];
}
/*
// Corner Points
*/
// Left-UP
p_cornerpoints = &m_dataMesh[0][0];
p_cornerpoints->vpNeighbours[4] = &m_dataMesh[1][0];
p_cornerpoints->vpNeighbours[7] = &m_dataMesh[1][1];
p_cornerpoints->vpNeighbours[6] = &m_dataMesh[0][1];
// Right-Up
p_cornerpoints = &m_dataMesh[meshwidth - 1][0];
p_cornerpoints->vpNeighbours[3] = &m_dataMesh[meshwidth - 2][0];
p_cornerpoints->vpNeighbours[5] = &m_dataMesh[meshwidth - 2][1];
p_cornerpoints->vpNeighbours[6] = &m_dataMesh[meshwidth - 1][1];
// Left-Down
p_cornerpoints = &m_dataMesh[0][meshheight - 1];
p_cornerpoints->vpNeighbours[1] = &m_dataMesh[0][meshheight - 2];
p_cornerpoints->vpNeighbours[2] = &m_dataMesh[1][meshheight - 1];
p_cornerpoints->vpNeighbours[4] = &m_dataMesh[1][meshheight - 1];
//Right-Down
p_cornerpoints = &m_dataMesh[meshwidth - 1][meshheight - 1];

p_cornerpoints->vpNeighbours[1] = &m_dataMesh[meshwidth - 1][meshheight - 2];


p_cornerpoints->vpNeighbours[0] = &m_dataMesh[meshwidth - 2][meshheight - 2];
p_cornerpoints->vpNeighbours[3] = &m_dataMesh[meshwidth - 2][meshheight - 1];

void Springdatastructure::linkDataPointsSimple(void)
{
//Inner Rectangle
int meshwidth = m_dataMesh.size();
int meshheight = m_dataMesh[0].size();
Pointdata* p_cornerpoints;
Pointdata* p_pointdata;

for (int i = 0; i < meshwidth - 1; i++)


{
for (int j = 0; j < meshheight - 1; j++)
{
p_pointdata = &m_dataMesh[i][j];
// Top Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[i][j - 1];
// Mid Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[i - 1][j];
p_pointdata->vpNeighbours[2] = &m_dataMesh[i + 1][j];

// Bottom Row
p_pointdata->vpNeighbours[3] = &m_dataMesh[i][j + 1];

}
// Top Lane
for (int i = 1; i < meshwidth - 1; i++)
{
p_pointdata = &m_dataMesh[i][0];
// Mid Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[i - 1][0];
p_pointdata->vpNeighbours[2] = &m_dataMesh[i + 1][0];

// Bottom Row
p_pointdata->vpNeighbours[3] = &m_dataMesh[i][1];

// Bottom Lane
for (int i = 1; i < meshwidth - 1; i++)
{
p_pointdata = &m_dataMesh[i][meshheight - 1];
// Top Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[i][meshheight - 2];
// Mid Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[i - 1][meshheight - 1];
p_pointdata->vpNeighbours[2] = &m_dataMesh[i + 1][meshheight - 1];
}
// Left Lane
for (int j = 1; j < meshheight - 1; j++)
{
p_pointdata = &m_dataMesh[0][j];
// Right Row
p_pointdata->vpNeighbours[2] = &m_dataMesh[1][j];

// Mid Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[0][j - 1];
p_pointdata->vpNeighbours[3] = &m_dataMesh[0][j + 1];

// Right Lane
for (int j = 1; j < meshheight - 1; j++)
{
p_pointdata = &m_dataMesh[meshwidth - 1][j];
// Left Row
p_pointdata->vpNeighbours[1] = &m_dataMesh[meshwidth - 2][j];

// Mid Row
p_pointdata->vpNeighbours[0] = &m_dataMesh[meshwidth - 1][j - 1];
p_pointdata->vpNeighbours[3] = &m_dataMesh[meshwidth - 1][j + 1];

/*
// Corner Points
*/
// Left-UP
p_cornerpoints = &m_dataMesh[0][0];
p_cornerpoints->vpNeighbours[2] = &m_dataMesh[1][0];
p_cornerpoints->vpNeighbours[3] = &m_dataMesh[0][1];
// Right-Up
p_cornerpoints = &m_dataMesh[meshwidth - 1][0];
p_cornerpoints->vpNeighbours[1] = &m_dataMesh[meshwidth - 2][0];
p_cornerpoints->vpNeighbours[3] = &m_dataMesh[meshwidth - 1][1];
// Left-Down
p_cornerpoints = &m_dataMesh[0][meshheight - 1];
p_cornerpoints->vpNeighbours[0] = &m_dataMesh[0][meshheight - 2];
p_cornerpoints->vpNeighbours[2] = &m_dataMesh[1][meshheight - 1];
//Right-Down
p_cornerpoints = &m_dataMesh[meshwidth - 1][meshheight - 1];
p_cornerpoints->vpNeighbours[0] = &m_dataMesh[meshwidth - 1][meshheight - 2];
p_cornerpoints->vpNeighbours[1] = &m_dataMesh[meshwidth - 2][meshheight - 1];
}
void Springdatastructure::calculateNodeForces(void)
{

if (m_calculationtype == SIMPLECALCULATION)
{
calculateForcesSimple();
}
else if (m_calculationtype == ADVANCEDCALCULATION)
{
calculateForcesSimple();
calculateForcesAdvanced();
}

void Springdatastructure::calculateForcesSimple(void)
{
int meshwidth = m_dataMesh.size();
int meshheight = m_dataMesh[0].size();
int ineighbourcount = 0;
vector<CHVector> vtemp;
Pointdata* pdata;
vtemp.resize(4);

for (int i = 0; i < meshwidth; i++)


{
for (int j = 0; j < meshheight; j++)
{
//TODO
pdata = &m_dataMesh[i][j];
}
}

void Springdatastructure::calculateForcesAdvanced(void)
{
//TODO
}

StructureVisualisation - !!! DRAFT !!!


#define RADIUS 0.1f
#define LONGITUTDE 8
#define LATTITUDE 4
StructureVisualisation::StructureVisualisation(vector<vector<Pointdata>>& springDataMesh)
{
m_springDataMesh = &springDataMesh;
m_sphereMaterial.MakeTextureImage("textures\\white_image.jpg");
}
StructureVisualisation::~StructureVisualisation()
{
}
void StructureVisualisation::setDatastructure(vector<vector<Pointdata>>& springDataMesh)
{
m_springDataMesh = &springDataMesh;
}
/*
* Adds Spheres to each node
*/
void StructureVisualisation::createSpheres(void)
{
int width = m_springDataMesh->size();
vector<vector<Pointdata>>* pvector = m_springDataMesh;
int height = m_springDataMesh[0].size();
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
CGeoSphere geosphere;
sGeoPlacement* psGeoPlacement = &m_placementmesh.subplacements[i][j];
geosphere.Init(RADIUS, &m_sphereMaterial, LONGITUTDE, LATTITUDE);

psGeoPlacement->geosphere = geosphere;
psGeoPlacement->placement.AddGeo(&geosphere);
psGeoPlacement->placement.Translate(m_springDataMesh[0][i][j].gridpoint);
m_placementmesh.placement.AddPlacement(&psGeoPlacement->placement);
geosphere.Fini();
}

}
/*
* Update Sphere Position
*/
void StructureVisualisation::updateSpheres(void)
{
int width = m_springDataMesh->size();
int height = m_springDataMesh[0].size();
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
// TODO: Translate Delta
CPlacement* pPlacement = &m_placementmesh.subplacements[i][j].placement;
CHVector placementTranslation = pPlacement->GetTranslation();
CHVector newPostion = m_springDataMesh[0][i][j].gridpoint;
placementTranslation - newPostion;
pPlacement->TranslateDelta(placementTranslation);
}
}
}

You might also like