Skip to content

Commit

Permalink
Fixed - Generation of 2D surface was completely broken, and has now b…
Browse files Browse the repository at this point in the history
…een completely rewritten. Added 'colourScale', 'useColourScale', and 'useDataForZ' accessors to GridVariable.
  • Loading branch information
trisyoungs committed Nov 29, 2012
1 parent 3c4afa5 commit 6aa3af8
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 63 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(Aten)
set(DESCRIPTION "Aten - Atomic configuration builder and editor")
set(AUTHOR "Tristan Youngs")
set(VERSION_MAJOR "1")
set(VERSION_MINOR "843")
set(VERSION_MINOR "844")
set(VERSION_PATCH "1")

set(CMAKE_BUILD_TYPE "Release")
Expand Down
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<h1>Manual TODO</h1>

<ul>
<li>Add 'colourScale', 'useColourScale', and 'useDataForZ' accessors to GridVariable.</li>
<li>Add 'repeatCellNegative' and 'repeatCellPositive' accessors to ModelVariable.</li>
<li>Add MatrixVariable description.</li>
<li>Add 'newPattern' and 'clearPattern' functions to ModelVariable</li>
Expand Down
2 changes: 1 addition & 1 deletion aten.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Name, brief description, and version
Summary: Aten - Atomic configuration builder and editor
Name: %{shortname}
Version: 1.843
Version: 1.844
Release: 1
License: GPL
%define fullname %{name}-%{version}
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AC_PREREQ(2.60)

# Set program name, version, bug-address and source directory
m4_define([ATEN_VERSION],[1.843])
m4_define([ATEN_VERSION],[1.844])
AC_INIT(aten,ATEN_VERSION,[email protected])
AC_CONFIG_SRCDIR([src/main.cpp])

Expand Down
4 changes: 2 additions & 2 deletions extra/aten.dsc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Format: 1.0
Source: aten
Version: 1.843
Version: 1.844
Binary: aten
Maintainer: Tristan Youngs <[email protected]>
Architecture: any
Build-Depends: debhelper (>= 4.1.16), libqt4-dev | libqt4-core, libqt4-opengl-dev, libreadline5-dev | libreadline-dev, libgl1-mesa-dev, pkgconfig | pkg-config, libncurses5
Files:
3da5e5936e1692219f327f9e2ea3df17 4301425 aten-1.843.tar.gz
cc798942ac2bb034b7ab1c301106f4b4 4301223 aten-1.844.tar.gz
2 changes: 1 addition & 1 deletion src/classes/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool Grid::initialise(GridType gt, Vec3<int> npoints)
case (Grid::RegularXYData):
nPoints_ = npoints;
result = allocateArrays();
if (result) msg.print("Initialised grid structure for regular 2D XY data, %i points total.\n", nPoints_.x*nPoints_.y*nPoints_.z);
if (result) msg.print("Initialised grid structure for regular 2D XY data, %i points total.\n", nPoints_.x*nPoints_.y);
break;
case (Grid::RegularXYZData):
nPoints_ = npoints;
Expand Down
4 changes: 2 additions & 2 deletions src/main/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#ifndef ATEN_VERSION_H
#define ATEN_VERSION_H

#define ATENVERSION "1.843"
#define ATENREVISION "1843"
#define ATENVERSION "1.844"
#define ATENREVISION "1844"
#define ATENDATE "Thu 28 Jun - 13:36"
#define ATENURL "http://aten.googlecode.com/svn/trunk"

Expand Down
22 changes: 22 additions & 0 deletions src/parser/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ GridVariable::~GridVariable()
Accessor GridVariable::accessorData[GridVariable::nAccessors] = {
{ "axes", VTypes::CellData, 0, TRUE },
{ "colour", VTypes::DoubleData, 4, FALSE },
{ "colourScale", VTypes::IntegerData, 0, FALSE },
{ "cutoff", VTypes::DoubleData, 0, FALSE },
{ "name", VTypes::StringData, 0, FALSE },
{ "nx", VTypes::IntegerData, 0, TRUE },
Expand All @@ -70,6 +71,8 @@ Accessor GridVariable::accessorData[GridVariable::nAccessors] = {
{ "shiftY", VTypes::IntegerData, 0, FALSE },
{ "shiftZ", VTypes::IntegerData, 0, FALSE },
{ "upperCutoff", VTypes::DoubleData, 0, FALSE },
{ "useColourScale", VTypes::IntegerData, 0, FALSE },
{ "useDataForZ", VTypes::IntegerData, 0, FALSE },
{ "visible", VTypes::IntegerData, 0, FALSE }
};

Expand Down Expand Up @@ -188,6 +191,9 @@ bool GridVariable::retrieveAccessor(int i, ReturnValue &rv, bool hasArrayIndex,
if (hasArrayIndex) rv.set( ptr->primaryColour()[arrayIndex-1] );
else rv.setArray( VTypes::DoubleData, ptr->primaryColour(), 4);
break;
case (GridVariable::ColourScale):
rv.set(ptr->colourScale()+1);
break;
case (GridVariable::Cutoff):
rv.set(ptr->lowerPrimaryCutoff());
break;
Expand Down Expand Up @@ -230,6 +236,12 @@ bool GridVariable::retrieveAccessor(int i, ReturnValue &rv, bool hasArrayIndex,
case (GridVariable::UpperCutoff):
rv.set(ptr->upperPrimaryCutoff());
break;
case (GridVariable::UseColourScale):
rv.set(ptr->useColourScale());
break;
case (GridVariable::UseDataForZ):
rv.set(ptr->useDataForZ());
break;
case (GridVariable::Visible):
rv.set(ptr->isVisible());
break;
Expand Down Expand Up @@ -317,6 +329,10 @@ bool GridVariable::setAccessor(int i, ReturnValue &sourcerv, ReturnValue &newval
else if (hasArrayIndex) ptr->primaryColour()[arrayIndex-1] = newvalue.asDouble(result);
else for (n=0; n<4; ++n) ptr->primaryColour()[n] = newvalue.asDouble(result);
break;
case (GridVariable::ColourScale):
ptr->setColourScale( newvalue.asInteger()-1 );
ptr->setUseColourScale( ptr->colourScale() != 0 );
break;
case (GridVariable::Cutoff):
ptr->setLowerPrimaryCutoff( newvalue.asDouble() );
break;
Expand Down Expand Up @@ -355,6 +371,12 @@ bool GridVariable::setAccessor(int i, ReturnValue &sourcerv, ReturnValue &newval
case (GridVariable::UpperCutoff):
ptr->setUpperPrimaryCutoff( newvalue.asDouble() );
break;
case (GridVariable::UseColourScale):
ptr->setUseColourScale( newvalue.asBool() );
break;
case (GridVariable::UseDataForZ):
ptr->setUseDataForZ( newvalue.asBool() );
break;
case (GridVariable::Visible):
ptr->setVisible( newvalue.asBool() );
break;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GridVariable : public PointerVariable
*/
public:
// Accessor list
enum Accessors { Axes, Colour, Cutoff, Name, NX, NY, NZ, Origin, OutlineVolume, Periodic, SecondaryColour, SecondaryCutoff, SecondaryUpperCutoff, ShiftX, ShiftY, ShiftZ, Visible, UpperCutoff, nAccessors };
enum Accessors { Axes, Colour, ColourScale, Cutoff, Name, NX, NY, NZ, Origin, OutlineVolume, Periodic, SecondaryColour, SecondaryCutoff, SecondaryUpperCutoff, ShiftX, ShiftY, ShiftZ, Visible, UpperCutoff, UseColourScale, UseDataForZ, nAccessors };
// Function list
enum Functions { Data, Shift, nFunctions };
// Search variable access list for provided accessor
Expand Down
133 changes: 79 additions & 54 deletions src/render/primitive_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,76 +514,101 @@ void GridPrimitive::createSurfaceMarchingCubes()
// Render normal '2D' surface
void GridPrimitive::createSurface2D()
{
int i, j;
Vec3<double> r, gradientx, gradienty, normal;
int cscale;
int i, j, n;
Vec3<double> normal[4];
int cscale = source_->useColourScale() ? source_->colourScale() : -1;
Vec3<int> npoints = source_->nPoints();
GLfloat colour[4], poscol[4];
GLfloat col1[4], col2[4], minalpha1, minalpha2;
double **data;
bool usez = source_->useDataForZ();

// Grab the data pointer and surface cutoff
data = source_->data2d();

// Set colour / transparency for surface
prefs.copyColour(Prefs::SpecularColour, colour);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, colour);
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, prefs.shininess());
cscale = source_->useColourScale() ? source_->colourScale() : -1;
if (cscale == -1) source_->copyPrimaryColour(poscol);
// Grab colours (if not using a colourscale) and determine colour mode to use
if (cscale == -1)
{
source_->copyPrimaryColour(col1);
source_->copySecondaryColour(col2);
primaryPrimitive_.setColourData(FALSE);
secondaryPrimitive_.setColourData(FALSE);
minalpha1 = col1[3];
minalpha2 = col2[3];
}
else
{
primaryPrimitive_.setColourData(TRUE);
secondaryPrimitive_.setColourData(TRUE);
minalpha1 = 1.0f;
minalpha2 = 1.0f;
}

// Render surface
for (i = 1; i<npoints.x-2; i++)
// Clear primitive data
primaryPrimitive_.clear();
secondaryPrimitive_.clear();

int di = 0, di2 = 2, dj, dj2;
for (i = 0; i<npoints.x-1; ++i)
{
for (j = 1; j<npoints.y-2; j++)
if (i == npoints.x-2) di2 = 1;
dj = 0;
dj2 = 2;
for (j = 0; j<npoints.y-1; ++j)
{
gradientx.set(1.0,0,(data[i+1][j] - data[i-1][j])*0.5);
gradienty.set(0,1.0,(data[i][j+1] - data[i][j-1])*0.5);
normal = (gradientx * gradienty);
normal.normalise();
if (j == npoints.y-2) dj2 = 1;
// Calculate normals...
normal[0] = Vec3<double>(1.0,0.0,(data[i+1][j] - data[i-di][j])*0.5) * Vec3<double>(0.0,1.0,(data[i][j+1] - data[i][j-dj])*0.5); // N(i,j)
normal[1] = Vec3<double>(1.0,0.0,(data[i+di2][j] - data[i][j])*0.5) * Vec3<double>(0.0,1.0,(data[i+1][j+1] - data[i+1][j-dj])*0.5); // N(i+1,j)
normal[2] = Vec3<double>(1.0,0.0,(data[i+1][j+1] - data[i-di][j+1])*0.5) * Vec3<double>(0.0,1.0,(data[i][j+dj2] - data[i][j])*0.5); // N(i,j+1)
normal[3] = Vec3<double>(1.0,0.0,(data[i+di2][j+1] - data[i][j+1])*0.5) * Vec3<double>(0.0,1.0,(data[i+1][j+dj2] - data[i+1][j])*0.5); // N(i+1,j+1)
for (n=0; n<4; ++n) normal[n].normalise();

// Set triangle coordinates and add cube position
if (cscale != -1)
{
prefs.colourScale[cscale].colour(data[i][j], colour);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colour);
}
glNormal3d(normal.x, normal.y, normal.z);
glVertex3d(i, j, usez ? data[i][j] : 0.0);
// First triangle
prefs.colourScale[cscale].colour(data[i][j], col1);
primaryPrimitive_.defineVertex(i, j, usez ? data[i][j] : 0.0, normal[0].x, normal[0].y, normal[0].z, col1[0], col1[1], col1[2], col1[3], TRUE);
if (col1[3] < minalpha1) minalpha1 = col1[3];

prefs.colourScale[cscale].colour(data[i+1][j], col1);
primaryPrimitive_.defineVertex(i+1, j, usez ? data[i+1][j] : 0.0, normal[1].x, normal[1].y, normal[1].z, col1[0], col1[1], col1[2], col1[3], TRUE);
if (col1[3] < minalpha1) minalpha1 = col1[3];

prefs.colourScale[cscale].colour(data[i][j+1], col1);
primaryPrimitive_.defineVertex(i, j+1, usez ? data[i][j+1] : 0.0, normal[2].x, normal[2].y, normal[2].z, col1[0], col1[1], col1[2], col1[3], TRUE);
if (col1[3] < minalpha1) minalpha1 = col1[3];

// Second triangle
primaryPrimitive_.defineVertex(i, j+1, usez ? data[i][j+1] : 0.0, normal[2].x, normal[2].y, normal[2].z, col1[0], col1[1], col1[2], col1[3], TRUE);

prefs.colourScale[cscale].colour(data[i+1][j], col1);
primaryPrimitive_.defineVertex(i+1, j, usez ? data[i+1][j] : 0.0, normal[1].x, normal[1].y, normal[1].z, col1[0], col1[1], col1[2], col1[3], TRUE);
if (col1[3] < minalpha1) minalpha1 = col1[3];

gradientx.set(1.0,0,(data[i+2][j] - data[i][j])*0.5);
gradienty.set(0,1.0,(data[i+1][j+1] - data[i+1][j-1])*0.5);
normal = gradientx * gradienty;
normal.normalise();
if (cscale != -1)
{
prefs.colourScale[cscale].colour(data[i+1][j], colour);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colour);
prefs.colourScale[cscale].colour(data[i+1][j+1], col1);
primaryPrimitive_.defineVertex(i+1, j+1, usez ? data[i+1][j+1] : 0.0, normal[3].x, normal[3].y, normal[3].z, col1[0], col1[1], col1[2], col1[3], TRUE);
if (col1[3] < minalpha1) minalpha1 = col1[3];
}
glNormal3d(normal.x, normal.y, normal.z);
glVertex3d(i+1, j, usez ? data[i+1][j] : 0.0);

gradientx.set(1.0,0,(data[i+2][j+1] - data[i][j+1])*0.5);
gradienty.set(0,1.0,(data[i+1][j+2] - data[i+1][j])*0.5);
normal = gradientx * gradienty;
normal.normalise();
if (cscale != -1)
else
{
prefs.colourScale[cscale].colour(data[i+1][j+1], colour);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colour);
// First triangle
primaryPrimitive_.defineVertex(i, j, usez ? data[i][j] : 0.0, normal[0].x, normal[0].y, normal[0].z, TRUE);
primaryPrimitive_.defineVertex(i+1, j, usez ? data[i+1][j] : 0.0, normal[1].x, normal[1].y, normal[1].z, TRUE);
primaryPrimitive_.defineVertex(i, j+1, usez ? data[i][j+1] : 0.0, normal[2].x, normal[2].y, normal[2].z, TRUE);

// Second triangle
primaryPrimitive_.defineVertex(i, j+1, usez ? data[i][j+1] : 0.0, normal[2].x, normal[2].y, normal[2].z, TRUE);
primaryPrimitive_.defineVertex(i+1, j, usez ? data[i+1][j] : 0.0, normal[1].x, normal[1].y, normal[1].z, TRUE);
primaryPrimitive_.defineVertex(i+1, j+1, usez ? data[i+1][j+1] : 0.0, normal[3].x, normal[3].y, normal[3].z, TRUE);
}
glNormal3d(normal.x, normal.y, normal.z);
glVertex3d(i+1, j+1, usez ? data[i+1][j+1] : 0.0);
dj = 1;

gradientx.set(1.0,0,(data[i+1][j+1] - data[i-1][j+1])*0.5);
gradienty.set(0,1.0,(data[i][j+2] - data[i][j])*0.5);
normal = gradientx * gradienty;
normal.normalise();
if (cscale != -1)
{
prefs.colourScale[cscale].colour(data[i][j+1], colour);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, colour);
}
glNormal3d(normal.x, normal.y, normal.z);
glVertex3d(i, j+1, usez ? data[i][j+1] : 0.0);
}
di = 1;
}
glEnd();

// Set transparency flags
primaryIsTransparent_ = (minalpha1 <= 0.99f);
secondaryIsTransparent_ = (minalpha2 <= 0.99f);
}

0 comments on commit 6aa3af8

Please sign in to comment.