MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PossibleContactList.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef POSSIBLECONTACTLIST_H
27 #define POSSIBLECONTACTLIST_H
28 
29 #include "PossibleContact.h"
30 
44 {
45 public:
46 
51  {
52  firstPossibleContact_ = nullptr;
53  logger(DEBUG, "PossibleContactList() constructor finished.");
54  }
55 
65  {
66  firstPossibleContact_ = new PossibleContact(P1, P2, firstPossibleContact_, P1->getFirstPossibleContact(), P2->getFirstPossibleContact());
67  P1->setFirstPossibleContact(firstPossibleContact_);
68  P2->setFirstPossibleContact(firstPossibleContact_);
75  logger(VERBOSE, "Added new possible contact between particles % and % ", P1->getIndex(), P2->getIndex());
76  }
77 
88  {
89  logger(VERBOSE, "Removing all contacts of particle %.", P->getIndex());
90  //The BaseParticle that shares a PossibleContact with P.
91  BaseParticle* O;
92  //The next possible contact for P.
93  PossibleContact* Next;
94  //The current possible contact for P.
95  PossibleContact* Curr = P->getFirstPossibleContact();
96  while (Curr != nullptr)
97  {
98  logger(VERBOSE, "Removing possible contacts index = % between particles % and %.", Curr->getIndex(), Curr->getP1()->getIndex(), Curr->getP2()->getIndex());
99  Next = Curr->getNext(P);
100  O = Curr->getOtherParticle(P);
101  //Set the pointers of the next global possible contact.
102  if (Curr->getNext())
103  Curr->getNext()->setPreviousPosition(Curr->getPrevious());
104 
105  //Set the pointers of the previous possible contact.
106  if (Curr->getPrevious())
107  Curr->getPrevious()->setNextPosition(Curr->getNext());
108  else
109  firstPossibleContact_ = Curr->getNext();
110 
111  //Set the pointers of the other object of the possible contact.
112  if (Curr->getNext(O))
113  Curr->getNext(O)->setPreviousPosition(O, Curr->getPrevious(O));
114 
115  if (Curr->getPrevious(O))
116  Curr->getPrevious(O)->setNextPosition(O, Curr->getNext(O));
117  else
118  O->setFirstPossibleContact(Curr->getNext(O));
119 
120  //Delete the possible contact and update the the pointer Curr to the
121  //next possible contact with P.
122  delete Curr;
123  Curr = Next;
124  }
125  P->setFirstPossibleContact(nullptr);
126  }
127 
132  void write(std::ostream& os) const
133  {
134  os << "Possible contacts are: " << std::endl;
136  while(it != nullptr)
137  {
138  os << *it << std::endl;
139  it = it->getNext();
140  }
141  }
142 
148  {
149  return firstPossibleContact_;
150  }
151 
152 private:
159 
160 };
161 
162 #endif
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle...
PossibleContact * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
void remove_ParticlePosibleContacts(BaseParticle *P)
Remove all PossibleContact with given BaseParticle from the linked list.
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
PossibleContactList()
Constructor, sets the firstPossibleContact_ to a nullptr since there are no possible interactions yet...
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
Manages the linked list of PossibleContact.
void write(std::ostream &os) const
Write all PossibleContact to the given ostream.
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
void add_PossibleContact(BaseParticle *P1, BaseParticle *P2)
Add the possible contact between two given BaseParticle to the linked list.
Class that describes a possible contact between two BaseParticle.
PossibleContact * getFirstPossibleContact()
Get the front of the linked list of PossibleContact.
int getIndex()
Gets the index of this PossibleContact.