Index: src/boundary.cpp
===================================================================
--- src/boundary.cpp	(revision 36ec71f4484a1913d51cd83e623c516fde7c113f)
+++ src/boundary.cpp	(revision d30402b028f6482fde29f70c53eebba7e5dd62aa)
@@ -760,29 +760,21 @@
 }
 
-/** Determines the volume of a cluster.
- * Determines first the convex envelope, then tesselates it and calculates its volume.
+/** Tesselates the convex boundary by finding all boundary points.
  * \param *out output stream for debugging
+ * \param *mol molecule structure with Atom's and Bond's
+ * \param *TesselStruct Tesselation filled with points, lines and triangles on boundary on return
+ * \param *LCList atoms in LinkedCell list
  * \param *filename filename prefix for output of vertex data
- * \param *configuration needed for path to store convex envelope file
- * \param *BoundaryPoints NDIM set of boundary points on the projected plane per axis, on return if desired
- * \param *mol molecule structure representing the cluster
- * \return determined volume of the cluster in cubed config:GetIsAngstroem()
- */
-double
-VolumeOfConvexEnvelope(ofstream *out, const char *filename, config *configuration,
-    Boundaries *BoundaryPtr, molecule *mol)
-{
-  bool IsAngstroem = configuration->GetIsAngstroem();
+ * \return *TesselStruct is filled with convex boundary and tesselation is stored under \a *filename.
+ */
+void Find_convex_border(ofstream *out, molecule* mol, class Tesselation *&TesselStruct, class LinkedCell *LCList, const char *filename)
+{
   atom *Walker = NULL;
-  struct Tesselation *TesselStruct = new Tesselation;
   bool BoundaryFreeFlag = false;
-  Boundaries *BoundaryPoints = BoundaryPtr;
-  double volume = 0.;
-  double PyramidVolume = 0.;
-  double G, h;
-  Vector x, y;
-  double a, b, c;
-
-  //Find_non_convex_border(out, tecplot, *TesselStruct, mol); // Is now called from command line.
+  Boundaries *BoundaryPoints = NULL;
+
+  if (TesselStruct != NULL) // free if allocated
+    delete(TesselStruct);
+  TesselStruct = new class Tesselation;
 
   // 1. calculate center of gravity
@@ -793,28 +785,21 @@
   *out << Verbose(1) << "Translating system to Center of Gravity." << endl;
   Walker = mol->start;
-  while (Walker->next != mol->end)
-    {
-      Walker = Walker->next;
-      Walker->x.Translate(CenterOfGravity);
-    }
+  while (Walker->next != mol->end) {
+    Walker = Walker->next;
+    Walker->x.Translate(CenterOfGravity);
+  }
 
   // 3. Find all points on the boundary
-  if (BoundaryPoints == NULL)
-    {
+  if (BoundaryPoints == NULL) {
       BoundaryFreeFlag = true;
       BoundaryPoints = GetBoundaryPoints(out, mol);
-    }
-  else
-    {
+  } else {
       *out << Verbose(1) << "Using given boundary points set." << endl;
-    }
+  }
 
   // 4. fill the boundary point list
   for (int axis = 0; axis < NDIM; axis++)
-    for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner
-        != BoundaryPoints[axis].end(); runner++)
-      {
+    for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++)
         TesselStruct->AddPoint(runner->second.second);
-      }
 
   *out << Verbose(2) << "I found " << TesselStruct->PointsOnBoundaryCount
@@ -833,5 +818,5 @@
 
   // 5b. go through all lines, that are not yet part of two triangles (only of one so far)
-  TesselStruct->TesselateOnBoundary(out, configuration, mol);
+  TesselStruct->TesselateOnBoundary(out, mol);
 
   *out << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundaryCount
@@ -839,4 +824,53 @@
       << " lines and " << TesselStruct->PointsOnBoundaryCount << " points."
       << endl;
+
+  // 6. translate all points back from CoG
+  *out << Verbose(1) << "Translating system back from Center of Gravity."
+      << endl;
+  CenterOfGravity->Scale(-1);
+  Walker = mol->start;
+  while (Walker->next != mol->end)
+    {
+      Walker = Walker->next;
+      Walker->x.Translate(CenterOfGravity);
+    }
+
+  // 7. Store triangles in tecplot file
+  if (filename != NULL) {
+    string OutputName(filename);
+    OutputName.append(TecplotSuffix);
+    ofstream *tecplot = new ofstream(OutputName.c_str());
+    write_tecplot_file(out, tecplot, TesselStruct, mol, 0);
+    tecplot->close();
+    delete(tecplot);
+    ofstream *rasterplot = new ofstream(OutputName.c_str());
+    write_raster3d_file(out, rasterplot, TesselStruct, mol);
+    rasterplot->close();
+    delete(rasterplot);
+  }
+
+  // free reference lists
+  if (BoundaryFreeFlag)
+    delete[] (BoundaryPoints);
+
+};
+
+
+/** Determines the volume of a cluster.
+ * Determines first the convex envelope, then tesselates it and calculates its volume.
+ * \param *out output stream for debugging
+ * \param *TesselStruct Tesselation filled with points, lines and triangles on boundary on return
+ * \param *configuration needed for path to store convex envelope file
+ * \return determined volume of the cluster in cubed config:GetIsAngstroem()
+ */
+double
+VolumeOfConvexEnvelope(ofstream *out, class Tesselation *TesselStruct, class config *configuration)
+{
+  bool IsAngstroem = configuration->GetIsAngstroem();
+  double volume = 0.;
+  double PyramidVolume = 0.;
+  double G, h;
+  Vector x, y;
+  double a, b, c;
 
   // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
@@ -874,27 +908,4 @@
       << endl;
 
-  // 7. translate all points back from CoG
-  *out << Verbose(1) << "Translating system back from Center of Gravity."
-      << endl;
-  CenterOfGravity->Scale(-1);
-  Walker = mol->start;
-  while (Walker->next != mol->end)
-    {
-      Walker = Walker->next;
-      Walker->x.Translate(CenterOfGravity);
-    }
-
-  // 8. Store triangles in tecplot file
-  string OutputName(filename);
-  OutputName.append(TecplotSuffix);
-  ofstream *tecplot = new ofstream(OutputName.c_str());
-  write_tecplot_file(out, tecplot, TesselStruct, mol, 0);
-  tecplot->close();
-  delete(tecplot);
-
-  // free reference lists
-  if (BoundaryFreeFlag)
-    delete[] (BoundaryPoints);
-
   return volume;
 }
@@ -919,12 +930,13 @@
   bool IsAngstroem = configuration->GetIsAngstroem();
   Boundaries *BoundaryPoints = GetBoundaryPoints(out, mol);
+  class Tesselation *TesselStruct = NULL;
+  LinkedCell LCList(mol, 10.);
+  Find_convex_border(out, mol, TesselStruct, &LCList, NULL);
   double clustervolume;
   if (ClusterVolume == 0)
-    clustervolume = VolumeOfConvexEnvelope(out, NULL, configuration,
-        BoundaryPoints, mol);
+    clustervolume = VolumeOfConvexEnvelope(out, TesselStruct, configuration);
   else
     clustervolume = ClusterVolume;
-  double *GreatestDiameter = GetDiametersOfCluster(out, BoundaryPoints, mol,
-      IsAngstroem);
+  double *GreatestDiameter = GetDiametersOfCluster(out, BoundaryPoints, mol, IsAngstroem);
   Vector BoxLengths;
   int repetition[NDIM] =
@@ -1229,6 +1241,5 @@
  */
 void
-Tesselation::TesselateOnBoundary(ofstream *out, config *configuration,
-    molecule *mol)
+Tesselation::TesselateOnBoundary(ofstream *out, molecule *mol)
 {
   bool flag;
@@ -2792,4 +2803,5 @@
  * \param *mol molecule structure with Atom's and Bond's
  * \param *Tess Tesselation filled with points, lines and triangles on boundary on return
+ * \param *LCList atoms in LinkedCell list
  * \param *filename filename prefix for output of vertex data
  * \para RADIUS radius of the virtual sphere
