Commit 24ff0855 authored by Kristin Berry's avatar Kristin Berry
Browse files

Added a very rough draft of the boost graph to ControlNetwork

parent ef193d5d
Loading
Loading
Loading
Loading
+51 −6
Original line number Diff line number Diff line
@@ -372,6 +372,12 @@ namespace Isis {
       if (!cubeGraphNodes->contains(sn)) {
        cubeGraphNodes->insert(sn, new ControlCubeGraphNode(sn));
      }
      // if the graph doesn't have the sn
      if (!m_vertexMap.contains(sn)) {
        ImageVertex newVertex = boost::add_vertex(m_controlGraph); 
        m_vertexMap.insert(sn, newVertex);
  //    boost::put(indexMapAdaptor, newVertex, i); <-- what does this do? 
      }
    }

    foreach(ControlMeasure* measure, point->getMeasures()) {
@@ -393,10 +399,32 @@ namespace Isis {
              node->addConnection(neighborNode, point);
              neighborNode->addConnection(node, point);
            }

            // new graph:
            ImageConnection connection = boost::add_edge(m_vertexMap[serial],
                                                         m_vertexMap[sn],
                                                         m_controlGraph).first;
            m_controlGraph[connection].strength++;
          }
        }
      }
    }
  }

// temporary print graph to test
  QString ControlNet::GraphToString() const {
    // Iterate through the vertices and print them out
    QString graphString; 
    VertexIndexMap indexMap;
    typedef boost::graph_traits<Network>::vertex_iterator vertex_iter;
    std::pair<vertex_iter, vertex_iter> vp;
    for(vp = vertices(m_controlGraph); vp.first != vp.second; ++vp.first) {
      std::cout << indexMap[*vp.first] << " ----- " << indexMap[*vp.second] << std::endl;
//      graphString.append(" --- ");
//      graphString.append(indexMap[*vp.second]);
//      graphString.append('\n');
    }
    return graphString;
   }


@@ -436,9 +464,17 @@ namespace Isis {
    // make sure there is a node for every measure in this measure's parent
    for (int i = 0; i < point->GetNumMeasures(); i++) {
      QString sn = point->GetMeasure(i)->GetCubeSerialNumber();

      // old
      if (!cubeGraphNodes->contains(sn)) {
        cubeGraphNodes->insert(sn, new ControlCubeGraphNode(sn));
      }

      // if the graph doesn't have the sn (boost) 
      if (!m_vertexMap.contains(sn)) {
        ImageVertex newVertex = boost::add_vertex(m_controlGraph); 
        m_vertexMap.insert(sn, newVertex);
      }
    }

    // add the measure to the corresponding node
@@ -446,6 +482,8 @@ namespace Isis {
    ControlCubeGraphNode *node = (*cubeGraphNodes)[serial];
    node->addMeasure(measure);

    // new graph: add node to edge or vertex descriptor?? 

    // in this measure's node add connections to the other nodes reachable from
    // its point
    if (!point->IsIgnored() && !measure->IsIgnored()) {
@@ -459,6 +497,11 @@ namespace Isis {
            node->addConnection(neighborNode, point);
            neighborNode->addConnection(node, point);
          }
          // new graph (boost): 
          ImageConnection connection = boost::add_edge(m_vertexMap[serial],
                                                         m_vertexMap[sn],
                                                         m_controlGraph).first;
          m_controlGraph[connection].strength++;
        }
      }
    }
@@ -725,10 +768,12 @@ namespace Isis {
   * @returns The total number of edges in the bi-directional graph for images
   */
  int ControlNet::getEdgeCount() const {
    int total = 0;
    foreach (ControlCubeGraphNode * node, *cubeGraphNodes) {
      total += node->getAdjacentNodes().size();
    }
    int total = boost::num_edges(m_controlGraph); 

//  int total = 0;
//  foreach (ControlCubeGraphNode * node, *cubeGraphNodes) {
//    total += node->getAdjacentNodes().size();
//  }

    return total;
  }
+36 −1
Original line number Diff line number Diff line
@@ -31,13 +31,25 @@
#include <QMap>
#include <QVector>

// Boost includes
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>


template< typename A, typename B > class QHash;
template< typename T > class QList;
template< typename A, typename B > struct QPair;
template< typename T > class QSet;





class QMutex;
class QString;


namespace Isis {
  class Camera;
  class ControlMeasure;
@@ -225,6 +237,25 @@ namespace Isis {
      friend class ControlPoint;

    public:
      // Temporarily put these here: 
      struct Image {
        QString serial;
      };

      struct Connection {
        int strength = 0;
      };

      // typedefs to help cut down on templated type bloat
      typedef boost::adjacency_list<boost::setS, boost::listS, boost::undirectedS, Image, Connection> Network;
      typedef Network::vertex_descriptor ImageVertex;
      typedef Network::edge_descriptor ImageConnection;
      typedef std::map<ImageVertex, size_t> VertexIndexMap;
      typedef boost::associative_property_map<VertexIndexMap> VertexIndexMapAdaptor;
      typedef Network::out_edge_iterator ConnectionIterator;



      ControlNet();
      ControlNet(const ControlNet &other);
      ControlNet(const QString &filename, Progress *progress = 0);
@@ -244,6 +275,7 @@ namespace Isis {
      bool ContainsPoint(QString pointId) const;

      QList< QString > GetCubeSerials() const;
      QString GraphToString() const;
      QList< ControlCubeGraphNode * > GetCubeGraphNodes();
      QList< QList< QString > > GetSerialConnections() const;
      int getEdgeCount() const;
@@ -358,7 +390,10 @@ namespace Isis {
      QHash< QString, ControlPoint * > * points;

      //! hash ControlCubeGraphNodes by CubeSerialNumber
      QHash< QString, ControlCubeGraphNode * > * cubeGraphNodes;
      QHash< QString, ControlCubeGraphNode * > * cubeGraphNodes; // TODO : delete

      QHash<QString, ImageVertex> m_vertexMap; //!< The SN -> vertex hash for the boost graph
      Network m_controlGraph; //!< The boost graph
      QStringList *pointIds;
      QMutex *m_mutex;

+93 −93
Original line number Diff line number Diff line
@@ -241,11 +241,11 @@ int main() {
  net.AddPoint(p0);

  // test ignoring of measures
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";
  p0m1->SetIgnored(true);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";
  p0m1->SetIgnored(false);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";

  // add another point - testing case where measures are added to points which
  // are already added to a net.
@@ -261,30 +261,30 @@ int main() {
  p1m2->SetCubeSerialNumber("CHARLIE");
  p1->Add(p1m1);
  p1->Add(p1m2);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";

  // test ignoring of point
  cout << "testing setting point to ignored.......................\n";
  p1->SetIgnored(true);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";
  p1->SetIgnored(false);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";

  // test measure deletion
  cout << "testing measure deletion & addition....................\n";
  p0->Delete(p0m1);
  p0m1 = NULL;
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";
  p0m0 = new ControlMeasure;
  p0m0->SetCubeSerialNumber("DELTA");
  p0->Add(p0m0);
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";

  // test point deletion
  cout << "testing point deletion.................................\n";
  net.DeletePoint(p1);
  p1 = NULL;
//  cout << net.CubeGraphToString() << "\n";
  cout << net.GraphToString() << "\n";

  cout << "******* Done testing cube graph ***************\n\n\n";

@@ -582,67 +582,67 @@ int main() {
  //system("cat unitTest.output | sed -r s/`date +%Y-%m-%dT`\\[0-9:\\]\\{8\\}/2010-08-27T17:10:06/g > temp.output; mv temp.output unitTest.output");

  return 0;
#if 0

  // -------------------------------------------------------------------------
  // Testing the google protocol buffer methods added to the ControlNet class
  // SLA 6/30/09
  // -------------------------------------------------------------------------

  cout << "Enter input cnet: ";
  string inNet;
  cin >> inNet;
  string outFile;
  cout << "Enter output file (directory & prefix, no extension): ";
  cin >> outFile;

  ControlNet *cn1 = new ControlNet;
  cout << "Speed Test for ControlNet ...." << endl << endl;
  cout << "\nReading from the ascii file....    " << inNet << endl;
  std::clock_t start = std::clock();
//  cn1.ReadControl("/work1/tsucharski/protobuf/isis/nets/cnet.net");
//  cn1->ReadControl("/work1/tsucharski/protobuf/isis/nets/pntreg2.net");
//  cn1->ReadControl("/work1/tsucharski/protobuf/isis/nets/pntreg_combinedparts.net");
  cn1->ReadControl(inNet);
  std::cout << ((std::clock() - start) / (double)CLOCKS_PER_SEC) << " seconds \n";

  cout << "\nWriting to the binary file...." << endl;
  start = std::clock();
//  cn1.WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.bin");
//  cn1->WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.bin");
//  cn1->WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.bin");
  cn1->WritePB(outFile + ".bin");
  std::cout << ((std::clock() - start) / (double)CLOCKS_PER_SEC) << " seconds \n";
  delete cn1;

//  ControlNet cn2;
  ControlNet *cn2 = new ControlNet;

  cout << "\nReading from the binary file...." << endl;
  std::clock_t start2 = std::clock();
//  cn2.ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.bin");
//  cn2->ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.bin");
//  cn2->ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.bin");
  cn2->ReadPBControl(outFile + ".bin");
  std::cout << ((std::clock() - start2) / (double)CLOCKS_PER_SEC) << " seconds \n";

//  apLat = (*cn2)[2].AprioriLatitude();
//  cout<<"binaryNet AprioriLatitude = "<<apLat<<endl;

//cout << "\nConverting the binary to Pvl...." << endl;
//#if 0
//
//  // -------------------------------------------------------------------------
//  // Testing the google protocol buffer methods added to the ControlNet class
//  // SLA 6/30/09
//  // -------------------------------------------------------------------------
//
//  cout << "Enter input cnet: ";
//  string inNet;
//  cin >> inNet;
//  string outFile;
//  cout << "Enter output file (directory & prefix, no extension): ";
//  cin >> outFile;
//
//  ControlNet *cn1 = new ControlNet;
//  cout << "Speed Test for ControlNet ...." << endl << endl;
//  cout << "\nReading from the ascii file....    " << inNet << endl;
//  std::clock_t start = std::clock();
////  cn1.ReadControl("/work1/tsucharski/protobuf/isis/nets/cnet.net");
////  cn1->ReadControl("/work1/tsucharski/protobuf/isis/nets/pntreg2.net");
////  cn1->ReadControl("/work1/tsucharski/protobuf/isis/nets/pntreg_combinedparts.net");
//  cn1->ReadControl(inNet);
//  std::cout << ((std::clock() - start) / (double)CLOCKS_PER_SEC) << " seconds \n";
//
//  cout << "\nWriting to the binary file...." << endl;
//  start = std::clock();
////  cn1.WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.bin");
////  cn1->WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.bin");
////  cn1->WritePB("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.bin");
//  cn1->WritePB(outFile + ".bin");
//  std::cout << ((std::clock() - start) / (double)CLOCKS_PER_SEC) << " seconds \n";
//  delete cn1;
//
////  ControlNet cn2;
//  ControlNet *cn2 = new ControlNet;
//
//  cout << "\nReading from the binary file...." << endl;
//  std::clock_t start2 = std::clock();
//cn1.ConvertBinToPvl();
////  cn2.ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.bin");
////  cn2->ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.bin");
////  cn2->ReadPBControl("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.bin");
//  cn2->ReadPBControl(outFile + ".bin");
//  std::cout << ((std::clock() - start2) / (double)CLOCKS_PER_SEC) << " seconds \n";



  cout << "\nWriting to the Pvl file...." << endl;
  std::clock_t start3 = std::clock();
//  cn2.Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.pvl");
//  cn2->Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.pvl");
//  cn2->Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.pvl");
  cn2->Write(outFile + ".pvl");
  std::cout << ((std::clock() - start3) / (double)CLOCKS_PER_SEC) << " seconds \n";

#endif
//
////  apLat = (*cn2)[2].AprioriLatitude();
////  cout<<"binaryNet AprioriLatitude = "<<apLat<<endl;
//
////cout << "\nConverting the binary to Pvl...." << endl;
////std::clock_t start2 = std::clock();
////cn1.ConvertBinToPvl();
////std::cout<< ( ( std::clock() - start2 ) / (double)CLOCKS_PER_SEC ) <<" seconds \n";
//
//
//
//  cout << "\nWriting to the Pvl file...." << endl;
//  std::clock_t start3 = std::clock();
////  cn2.Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/cnet.pvl");
////  cn2->Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg2.pvl");
////  cn2->Write("/work1/tsucharski/protobuf/isis/nets/testMultiMsgs/pntreg_combinedparts.pvl");
//  cn2->Write(outFile + ".pvl");
//  std::cout << ((std::clock() - start3) / (double)CLOCKS_PER_SEC) << " seconds \n";
//
//#endif
}