Ejemplo n.º 1
0
int main(void)
{
    int maxSumArrayIndex = 0;

    /* Input parameters */
    inputParameters();
    printInputArray();

    /* Compute all sub arrays */
    computeAllSubArrays();

    /* find the sub array with max computed value */
    maxSumArrayIndex = findMaxArray();

    /* Print the input array and found sub array */
    printMaxArray(maxSumArrayIndex);

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, const char * argv[]) {
    int pictureWidth, pictureHeight;
    double minLongitude, maxLongitude;
    double minLatitude, maxLatitude;
    // Central parallel:
    double alpha_0 = 36.0;
    // Radius, 1.0 shoud be ok...
    double r_0 = 1.0;
    // Central meridian:
    double gamma_0 = -96.0;
    std::ifstream inputParameters("parameters.txt");
    inputParameters >> pictureWidth >> pictureHeight;
    inputParameters >> minLatitude >> maxLatitude;
    inputParameters >> minLongitude >> maxLongitude;
    inputParameters.close();
    
    // This will be used later
    double beta_0 = cos(alpha_0*M_PI/180.0)/tan(alpha_0*M_PI/180.0);
    double rho_0, theta_0;
    
    std::map<std::string, std::string> theCoveredDistricts;
    std::string theDistrict;
    std::string theStatus;
    std::ifstream districtsCovered("covered.txt");
    while (districtsCovered >> theDistrict >> theStatus) {
        theCoveredDistricts[ theDistrict ] = theStatus;
    }
    districtsCovered.close();
    
    double longitudeWindow = maxLongitude - minLongitude;
    double latitudeWindow = maxLatitude - minLatitude;
    double theLongitude, theLatitude;
    bool firstPoint;
    
    // xPx : [ 0, pictureWidth ], left to right
    // yPx : [ 0, pictureHeight ], top to bottom
    double xPx, yPx;
    double previousX = 0.0, previousY = 0.0;
    double deltaX, deltaY;
    
    std::ofstream theSVGFile("theMap.svg");
    theSVGFile << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
    theSVGFile << "<svg width=\"" << pictureWidth << "px\" height=\"" << pictureHeight << "px\" " ;
    theSVGFile << "viewBox=\"0 0 " << pictureWidth << ' ' << pictureHeight << "\" " ;
    theSVGFile << "xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl;
    std::time_t result = std::time(nullptr);
    theSVGFile << "<title>" << std::endl;
    theSVGFile << "DC trip 2015 - " << std::asctime(std::localtime(&result)) ;
    theSVGFile << "</title>" << std::endl;
    theSVGFile << "<desc>" << std::endl;
    theSVGFile << "Creator: Jesus Orduna" << std::endl;
    theSVGFile << "CreationDate: " << std::asctime(std::localtime(&result)) ;
    theSVGFile << "</desc>" << std::endl;
    theSVGFile << "<defs></defs>" << std::endl;
    theSVGFile << "<rect id=\"Sea\" x=\"0\" y=\"0\" fill=\"#C8EBFF\" width=\"" << pictureWidth << "\" height=\"" << pictureHeight << "\"/>" << std::endl;
    
    std::ifstream includeFiles("include.txt");
    std::string theFile;
    int scheduled = 0, pending = 0, denied = 0;
    while (includeFiles >> theFile) {
        std::ifstream theDistrictCoordinates(theFile.c_str());
        firstPoint = true;
        theSVGFile << "<a xlink:title=\"" << theFile.substr(4, 5) << "\">" << std::endl;
        theSVGFile << " <path id=\"" << theFile << "\" fill=\"" ;
        if ( theCoveredDistricts.count( theFile ) ) {
            if (theCoveredDistricts[ theFile ] == "Yes" ) {
                scheduled++;
                theSVGFile << "green\" opacity=\"0.5" ;
            } else if (theCoveredDistricts[ theFile ] == "Pending" ) {
                pending++;
                theSVGFile << "yellow\" opacity=\"0.5" ;
            } else {
                denied++;
                theSVGFile << "red\" opacity=\"0.5" ;
            }
        } else {
            theSVGFile << "#FDFCEA" ;
        }
        theSVGFile <<"\" stroke=\"#0978AB\" stroke-width=\"0.25\" d=\"" ;
        double xPxMin = 1.e100;
        while (theDistrictCoordinates >> theLongitude >> theLatitude) {
            rho_0 = r_0*(1.0/tan(alpha_0*M_PI/180.0)-tan((theLatitude-alpha_0)*M_PI/180.0));
            theta_0 = beta_0*(theLongitude - gamma_0)/360.0-M_PI_2;
            xPx = (rho_0*cos(theta_0)-minLongitude)*pictureWidth/longitudeWindow;
            yPx = pictureHeight*(1.0-(rho_0*sin(theta_0)-minLatitude)/latitudeWindow);
            
            if (xPx > 0 && xPx < pictureWidth) {
                if (xPx < xPxMin) { xPxMin = xPx; }
            }
            if (firstPoint) {
                theSVGFile << "M" << xPx << "," << yPx ;
                firstPoint = false;
            } else {
                deltaX = round(1000.*(xPx - previousX))/1000.;
                deltaY = round(1000.*(yPx - previousY))/1000.;
                if( deltaX == 0 && deltaY == 0 ) {
                } else {
                    if (deltaX == 0) {
                        theSVGFile << "v" << deltaY ;
                    } else {
                        if (deltaY == 0) {
                            theSVGFile << "h" << deltaX ;
                        } else {
                            theSVGFile << "l" << deltaX << "," << deltaY ;
                        }
                    }
                }
            }
            previousX = xPx;
            previousY = yPx;
        }
        theSVGFile << "z\"/>" << std::endl;
        theSVGFile << "</a>" << std::endl;
        theDistrictCoordinates.close();
    }
    includeFiles.close();
    
    std::ifstream theInstitutions("listOfInstitutions.txt");
    std::string theInstitution;
    while (!theInstitutions.eof()) {
        theInstitutions >> theLongitude >> theLatitude ;
        getline(theInstitutions, theInstitution);
        rho_0 = r_0*(1.0/tan(alpha_0*M_PI/180.0)-tan((theLatitude-alpha_0)*M_PI/180.0));
        theta_0 = beta_0*(theLongitude - gamma_0)/360.0-M_PI_2;
        xPx = (rho_0*cos(theta_0)-minLongitude)*pictureWidth/longitudeWindow;
        yPx = pictureHeight*(1.0-(rho_0*sin(theta_0)-minLatitude)/latitudeWindow);
        theSVGFile << "<a xlink:href=\"http://maps.google.com/?q=" << theLatitude << ',' << theLongitude << "\" ";
        theSVGFile << "xlink:title=\"" << theInstitution << "\">" << std::endl;
        theSVGFile << " <circle cx=\"" << xPx << "\" cy=\"" << yPx << "\" r=\"2\" fill=\"yellow\" stroke=\"red\" stroke-width=\".5\"/>" << std::endl;
        theSVGFile << "</a>" << std::endl;
    }
    theInstitutions.close();
    theSVGFile << "</svg>" << std::endl;
    theSVGFile.close();
    
    std::cout << " - - Summary - -" << std::endl;
    std::cout << "Confirmed meetings: " << scheduled << std::endl;
    std::cout << "Pending meetings: " << pending << std::endl;
    std::cout << "Denied meetings: " << denied << std::endl;
    return 0;
}
Ejemplo n.º 3
0
void GlobFit::dumpData(const std::vector<RelationEdge>& vecRelationEdge, const std::string& stageName)
{
  size_t maxVerticesNum = 0;
  for (size_t i = 0, iEnd = _vecPrimitive.size(); i < iEnd; ++ i) {
    Primitive* pPrimitive = _vecPrimitive[i];
    pPrimitive->prepareParameters();
    maxVerticesNum = std::max(pPrimitive->getPointIdx().size(), maxVerticesNum);
  }

  std::locale loc("C");

  std::string path = boost::filesystem::current_path().string();
  path = path+"/matlab/data/"+stageName+"/";
  boost::filesystem::create_directories(path);
  std::ofstream constraints((path+"constraints.dat").c_str());
  std::ofstream primitiveType((path+"primitiveType.dat").c_str());
  std::ofstream inputParameters((path+"inputParameters.dat").c_str());
  std::ofstream numVertices((path+"numVertices.dat").c_str());
  std::ofstream coordX((path+"coordX.dat").c_str());
  std::ofstream coordY((path+"coordY.dat").c_str());
  std::ofstream coordZ((path+"coordZ.dat").c_str());
  std::ofstream normalX((path+"normalX.dat").c_str());
  std::ofstream normalY((path+"normalY.dat").c_str());
  std::ofstream normalZ((path+"normalZ.dat").c_str());
  std::ofstream confVertices((path+"confVertices.dat").c_str());

  constraints.imbue(loc);
  primitiveType.imbue(loc);
  inputParameters.imbue(loc);
  inputParameters.precision(16);
  numVertices.imbue(loc);
  coordX.imbue(loc);
  coordX.precision(16);
  coordY.imbue(loc);
  coordY.precision(16);
  coordZ.imbue(loc);
  coordZ.precision(16);
  normalX.imbue(loc);
  normalX.precision(16);
  normalY.imbue(loc);
  normalY.precision(16);
  normalZ.imbue(loc);
  normalZ.precision(16);
  confVertices.imbue(loc);
  confVertices.precision(16);

  for (size_t i = 0, iEnd = vecRelationEdge.size(); i < iEnd; ++ i) {
    const RelationEdge& relationEdge = vecRelationEdge[i];
    constraints << relationEdge << std::endl;
  }

  for (size_t i = 0, iEnd = _vecPrimitive.size(); i < iEnd; ++ i) {
    Primitive* pPrimitive = _vecPrimitive[i];

    primitiveType << pPrimitive->getType() << std::endl;

    pPrimitive->prepareParameters();
    for (size_t j = 0, jEnd = Primitive::getNumParameter(); j < jEnd; ++ j) {
      inputParameters << pPrimitive->getParameter(j) << " ";
    }
    inputParameters << std::endl;

    numVertices << pPrimitive->getPointIdx().size() << std::endl;
    for (size_t j = 0, jEnd = pPrimitive->getPointIdx().size(); j < jEnd; ++ j) {
      const RichPoint* richPoint = _vecPointSet[pPrimitive->getPointIdx()[j]];
      const Point& point = richPoint->point;
      const Vector& normal = richPoint->normal;
      coordX << point.x() << " ";
      coordY << point.y() << " ";
      coordZ << point.z() << " ";
      normalX << normal.x() << " ";
      normalY << normal.y() << " ";
      normalZ << normal.z() << " ";
      confVertices << richPoint->confidence << " ";
    }

    for (size_t j = pPrimitive->getPointIdx().size(); j < maxVerticesNum; ++ j) {
      coordX << 0 << " ";
      coordY << 0 << " ";
      coordZ << 0 << " ";
      normalX << 0 << " ";
      normalY << 0 << " ";
      normalZ << 0 << " ";
      confVertices << 0 << " ";
    }
    coordX << std::endl;
    coordY << std::endl;
    coordZ << std::endl;
    normalX << std::endl;
    normalY << std::endl;
    normalZ << std::endl;
    confVertices << std::endl;
  }

  return;
}