~ubuntu-branches/ubuntu/quantal/python-demgengeo/quantal

« back to all changes in this revision

Viewing changes to src/ShapeList.cc

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2011-11-18 21:47:18 UTC
  • Revision ID: package-import@ubuntu.com-20111118214718-4ysqm3dhpqwdd7gd
Tags: upstream-0.99~bzr106
ImportĀ upstreamĀ versionĀ 0.99~bzr106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////
 
2
//                                                         //
 
3
// Copyright (c) 2007-2011 by The University of Queensland //
 
4
// Earth Systems Science Computational Centre (ESSCC)      //
 
5
// http://www.uq.edu.au/esscc                              //
 
6
//                                                         //
 
7
// Primary Business: Brisbane, Queensland, Australia       //
 
8
// Licensed under the Open Software License version 3.0    //
 
9
// http://www.opensource.org/licenses/osl-3.0.php          //
 
10
//                                                         //
 
11
/////////////////////////////////////////////////////////////
 
12
 
 
13
#include "ShapeList.h"
 
14
#include "HexAggregateShape.h"
 
15
 
 
16
void ShapeList::addHexShape(int bias, int random) {
 
17
  HexAggregateShape shape;
 
18
  shape.setBias(bias);
 
19
  shape.makeOrientationRandom(random);
 
20
  shapeList.push_back(&shape);
 
21
}
 
22
 
 
23
void ShapeList::insertShape(Vector3 pos, double radius, MNTable3D* ntable, int tag, int id) {
 
24
  std::vector<int> biasList;
 
25
  unsigned int i;
 
26
  int biasTotal=0;
 
27
  // at all bias values.
 
28
  for(i=0; i < shapeList.size() ; i++) {
 
29
    int currBias = shapeList[i]->bias();
 
30
    biasTotal = biasTotal + currBias;
 
31
    biasList.push_back ( currBias );
 
32
  }
 
33
 
 
34
  if ( biasTotal == 0 ) {
 
35
    return;
 
36
  }
 
37
 
 
38
  // at a random value to select a shape
 
39
  int randomValue = rand() % biasTotal;
 
40
  i=0;
 
41
  // Find appropriate shape in list.
 
42
  while ( randomValue > shapeList[i]->bias() ) {
 
43
    randomValue = randomValue - shapeList[i]->bias();
 
44
    i++;
 
45
    if (i == shapeList.size() ) {
 
46
      std::cerr << "Error in ShapeList::insertShape :> randomValue too high\n";
 
47
      return;
 
48
    }
 
49
  }
 
50
  shapeList[i]->insert(pos, radius, ntable, tag,id);
 
51
}
 
52
 
 
53
 
 
54
void ShapeList::addGenericShape(string db, string name, int bias, int random, 
 
55
    int particleTag, int bondTag) {
 
56
  shapeList.push_back(new GenericShape(db,name));
 
57
  Shape *shape = shapeList[shapeList.size()-1];
 
58
  shape->setBias(bias);
 
59
  shape->makeOrientationRandom(random);
 
60
  shape->setParticleTag(particleTag);
 
61
  shape->setBondTag(bondTag);
 
62
}
 
63