Exemplo n.º 1
0
void ReportMenu::go()
{
    system("clear");
    cout << "HKUST Course Registration System <Report Menu>" << endl;
    cout << "----------------------------------------------" << endl;
    cout << endl;
    cout << "1. List all student information" << endl;
    cout << "2. List all course information" << endl;
    cout << "3. List all courses of a student" << endl;
    cout << "4. List all students of a course" << endl;
    cout << "5. Go back to main menu" << endl;
    cout << endl;
    cout << "Enter your choice <1-5>: ";

    unsigned int choice = 0;
    while(true) {

        string input = "";
        getline(cin, input);
        if(input.empty()) continue;
        stringstream myStream(input);
        myStream >> choice;

        if(choice > 0 && choice < 6)
            break;

        cout << "Invalid input, re-enter again <1-5>: ";
    }

    try {subItem[choice - 1]->go();}
    catch(string err) {cout << err << endl << endl;}
    cout << "Press enter to go back" << endl;
    cin.get();
    subItem[4]->go();
}
Exemplo n.º 2
0
void FileMenu::go()
{
    system("clear");
    cout << "HKUST Course Registration System <File Menu>" << endl;
    cout << "--------------------------------------------" << endl;
    cout << endl;
    cout << "1. Save Database" << endl;
    cout << "2. Load Database" << endl;
    cout << "3. Go back to main menu" << endl;
    cout << endl;
    cout << "Enter your choice <1-3>: ";

    unsigned int choice = 0;
    while(true) {

        string input = "";
        getline(cin, input);
        if(input.empty()) continue;
        stringstream myStream(input);
        myStream >> choice;

        if(choice > 0 && choice < 4)
            break;

        cout << "Invalid input, re-enter again <1-3>: ";
    }

    try {subItem[choice - 1]->go();}
    catch(string err) {cout << err << endl << endl;}
    cout << "Press enter to go back" << endl;
    cin.get();
    subItem[2]->go();
}
Exemplo n.º 3
0
void MainMenu::go()
{
    system("clear");
    cout << "HKUST Course Registration System" << endl;
    cout << "--------------------------------" << endl;
    cout << endl;
    cout << "1. Student Management" << endl;
    cout << "2. Course Management" << endl;
    cout << "3. Course Registration" << endl;
    cout << "4. Report Management" << endl;
    cout << "5. File Management" << endl;
    cout << "6. Exit" << endl;
    cout << endl;
    cout << "Enter your choice <1-6>: ";

    unsigned int choice = 0;
    while(true) {

        string input = "";
        getline(cin, input);
        if(input.empty()) continue;
        stringstream myStream(input);
        myStream >> choice;

        if(choice > 0 && choice < 7)
            break;

        cout << "Invalid input, re-enter again <1-6>: ";
    }

    subItem[choice - 1]->go();
}
Exemplo n.º 4
0
void StudentMenu::go()
{
    system("clear");
    cout << "HKUST Course Registration System <Student Menu>" << endl;
    cout << "-----------------------------------------------" << endl;
    cout << endl;
    cout << "1. Insert Student Record" << endl;
    cout << "2. Modify Student Record" << endl;
    cout << "3. Delete Student Record" << endl;
    cout << "4. Query Student Record" << endl;
    cout << "5. Go Back to main menu" << endl;
    cout << endl;
    cout << "Enter your choice <1-5>: ";

    unsigned int choice = 0;
    while(true) {

        string input = "";
        getline(cin, input);
        if(input.empty()) continue;
        stringstream myStream(input);
        myStream >> choice;

        if(choice > 0 && choice < 6)
            break;

        cout << "Invalid input, re-enter again <1-5>: ";
    }

    try {subItem[choice - 1]->go();}
    catch(string err) {cout << err << endl << endl;}
    cout << "Press enter to go back" << endl;
    cin.get();
    subItem[4]->go();
}
void CameraSettings::LoadFromFile(const std::string& configFileName)
{     
    fstream myStream(configFileName.c_str());
    vector<Parameter> parameters;   
     
    SetDefaults();  // Set default values incase some are missing in the file.
    if (myStream.is_open())
    {
		while (not myStream.eof())
		{
			  Parameter p;
			  myStream >> p;
			  if (p.name().size() != 0)
				 parameters.push_back(p);
		}

        for(int i=0; i<parameters.size(); i++) {
            if(!SetByName(parameters[i]))
                debug << "CameraSettings::LoadFromFile(): \"" << parameters[i].name() << "\" not found." << endl;
            else
                debug << "CameraSettings::LoadFromFile(): " << parameters[i].name() << " " << parameters[i].get() <<
                         " [" << parameters[i].min() << ", " << parameters[i].max() << "]" << endl;
        }
        p_valid = true;
    }
    else
Exemplo n.º 6
0
Arquivo: Map.cpp Projeto: anliec/Mosp
Map::Map(std::string filePath)
{
    try{
        std::ifstream myStream(filePath);

        if(myStream)
        {
            char c;
            int line = 0;
            int i=0;
            while(myStream.get(c))
            {
                if(c != '\n')
                {
                    if(i >= tiles.size())
                    { //if the column doesn't exist
                        std::vector<Tile> column;
                        tiles.push_back(column); //add the column
                        //add the missing lines:
                        for (int y = 0; y < line; ++y)
                        {
                            tiles.at(i).push_back(Tile(Coordinate(i,line),TILE_UNWALKABLE));
                        }
                    }
                    int type;
                    if(std::isdigit(c))
                    {
                        type = std::atoi(&c);
                    }
                    else
                    {
                        type = TILE_UNWALKABLE;
                    }
                    tiles.at(i).push_back( Tile(Coordinate(i,line),type));
                    i++;
                }
                else
                {
                    i=0;
                    line++;
                }
            }
        }
        else
        {
            std::cerr << "ERROR WHEN LOADING FILE: " << filePath << std::endl;
        }
        myStream.close();
    }
    catch(std::exception const& e)
    {
        std::cerr << "ERROR WHEN LOADING FILE: " << filePath << std::endl << e.what() << std::endl;
        throw;
    }

}
Exemplo n.º 7
0
void KoalaDoctor::diagnose(SickKoala *patient)
{
  std::ofstream	myStream((patient->getName() + ".report").c_str());
  std::string	drugList[5] = {"mars", "Buronzand", "Viagra", "Extasy", "Feuille d'eucalyptus"} ;
  std::string	patientName;

  std::cout << "Dr." << this->name << ": Alors qu'est-ce qui vous goerk Mr." << patient->getName() << " ?" << std::endl;
  patient->poke();
  if (myStream)
    myStream << drugList[random() % 5];
}
Exemplo n.º 8
0
/**
 * Function getInteger
 * gets an integer from user input
 * @returns integer inputed by user
 */
int getInteger() {
    string input = "";
    int integer = 0;

    getline(cin, input);

    stringstream myStream(input);
    myStream >> integer;

    return integer;
}
Exemplo n.º 9
0
	AboutZino::AboutZino(QWidget* parent, Qt::WFlags fl)
: QDialog (parent,fl), AboutZinoBase()
{
	//required by Qt4 to initialise the ui
	setupUi(this);
	readSettings();
	qDebug("Reading license file");
	QFile myFile(":/LICENSE.txt");
	QTextStream myStream(&myFile);
	QApplication::setOverrideCursor(Qt::WaitCursor);
	teLicense->setPlainText(myStream.readAll());
	QApplication::restoreOverrideCursor();
}
Exemplo n.º 10
0
//the format defaults to "PNG" if not specified
void QgsMapCanvas::saveAsImage( const QString& theFileName, QPixmap * theQPixmap, const QString& theFormat )
{
  //
  //check if the optional QPaintDevice was supplied
  //
  if ( theQPixmap != NULL )
  {
    // render
    QPainter painter;
    painter.begin( theQPixmap );
    QgsMapRendererCustomPainterJob job( mSettings, &painter );
    job.start();
    job.waitForFinished();
    emit renderComplete( &painter );
    painter.end();

    theQPixmap->save( theFileName, theFormat.toLocal8Bit().data() );
  }
  else //use the map view
  {
    mMap->contentImage().save( theFileName, theFormat.toLocal8Bit().data() );
  }
  //create a world file to go with the image...
  QgsRectangle myRect = mapSettings().visibleExtent();
  QString myHeader;
  // note: use 17 places of precision for all numbers output
  //Pixel XDim
  myHeader += qgsDoubleToString( mapUnitsPerPixel() ) + "\r\n";
  //Rotation on y axis - hard coded
  myHeader += "0 \r\n";
  //Rotation on x axis - hard coded
  myHeader += "0 \r\n";
  //Pixel YDim - almost always negative - see
  //http://en.wikipedia.org/wiki/World_file#cite_note-2
  myHeader += '-' + qgsDoubleToString( mapUnitsPerPixel() ) + "\r\n";
  //Origin X (center of top left cell)
  myHeader += qgsDoubleToString( myRect.xMinimum() + ( mapUnitsPerPixel() / 2 ) ) + "\r\n";
  //Origin Y (center of top left cell)
  myHeader += qgsDoubleToString( myRect.yMaximum() - ( mapUnitsPerPixel() / 2 ) ) + "\r\n";
  QFileInfo myInfo  = QFileInfo( theFileName );
  // allow dotted names
  QString myWorldFileName = myInfo.absolutePath() + '/' + myInfo.completeBaseName() + '.' + theFormat + 'w';
  QFile myWorldFile( myWorldFileName );
  if ( !myWorldFile.open( QIODevice::WriteOnly ) ) //don't use QIODevice::Text
  {
    return;
  }
  QTextStream myStream( &myWorldFile );
  myStream << myHeader;
} // saveAsImage
Exemplo n.º 11
0
std::string	KoalaNurse::readReport(std::string file)
{
  std::ifstream	myStream(file.c_str());
  std::string	drug("");
  std::string	patientName;

  if (myStream)
    {
      patientName = file.substr(0, file.rfind(".report"));
      getline(myStream, drug);
      std::cout << "Nurse " << this->id << ": Kreog ! Il faut donner un " << drug << " a Mr." << patientName << " !" << std::endl;
    }
  return (drug);
}
Exemplo n.º 12
0
int main(int argc, char const *argv[])
{
	if(argc != 2)
	{
		std::cout << "Erro de sintaxe!" << std::endl;
		std::cout << "Use: bares <arquivo_de_leitura>" << std::endl;
		return EXIT_FAILURE;
	}

	std::string myFile = argv[1];
	std::cout << "Tentando abrir o arquivo [ " << myFile << " ]" << std::endl;
	std::ifstream myStream(myFile);

	if(!myStream)
	{
		std::cout << "Falha na abertura do arquivo";
		return EXIT_FAILURE;
	}
	else
	{
		std::cout << "Arquivo aberto com sucesso" << std::endl;
	}

	std::string expression;

	while(!myStream.eof())
	{
		QueueLL<token> exps;
		QueueLL<token> posFix;
		int result;

		getline(myStream, expression);

		if (stringToInfix(expression, exps))
		{
			if (infixToPosfix(exps, posFix))
			{
				if (calcPosfix(posFix, result))
				{
					std::cout << result << std::endl;

				}
			}
			std::cout << std::endl;
		}
	}

	return 0;
}
Exemplo n.º 13
0
int 
nsMsgSendPart::Write()
{
  int     status = 0;
  char    *separator = nsnull;
  PRBool  needToWriteCRLFAfterEncodedBody  = PR_FALSE;

#define PUSHLEN(str, length)                  \
  do {                            \
    status = mime_write_message_body(m_state, str, length); \
    if (status < 0) goto FAIL;                \
  } while (0)                         \

#define PUSH(str) PUSHLEN(str, PL_strlen(str))

  // rhp: Suppress the output of parts that are empty!
  if ( (m_parent) &&
       (m_numchildren == 0) &&
       ( (!m_buffer) || (!*m_buffer) ) &&
       (!m_filespec) &&
       (!m_mainpart) )
    return SKIP_EMPTY_PART;

  if (m_mainpart && m_type && PL_strcmp(m_type, TEXT_HTML) == 0) 
  {     
    if (m_filespec) 
    {
      // The "insert HTML links" code requires a memory buffer,
      // so read the file into memory.
      NS_ASSERTION(m_buffer == nsnull, "not-null buffer");
      PRInt32           length = 0;
      
      if (m_filespec->Valid())
        length = m_filespec->GetFileSize();
      
      m_buffer = (char *) PR_Malloc(sizeof(char) * (length + 1));
      if (m_buffer) 
      {
        nsInputFileStream file(*m_filespec);
        if (file.is_open()) 
        {
          length = file.read(m_buffer, length);
          file.close();
          m_buffer[length] = '\0';
        }
        else 
          PR_Free(m_buffer);
      }
    }
  }
  
  if (m_parent && m_parent->m_type &&
        !PL_strcasecmp(m_parent->m_type, MULTIPART_DIGEST) &&
        m_type &&
        (!PL_strcasecmp(m_type, MESSAGE_RFC822) ||
        !PL_strcasecmp(m_type, MESSAGE_NEWS))) 
  {
    // If we're in a multipart/digest, and this document is of type
    // message/rfc822, then it's appropriate to emit no headers.
    //
  }
  else 
  {
    char *message_headers = 0;
    char *content_headers = 0;
    char *content_type_header = 0;
    status = divide_content_headers(m_other,
                                    &message_headers,
                                    &content_headers,
                                    &content_type_header);
    if (status < 0)
      goto FAIL;
    
      /* First, write out all of the headers that refer to the message
      itself (From, Subject, MIME-Version, etc.)
    */
    if (message_headers) 
    {
      PUSH(message_headers);
      PR_Free(message_headers);
      message_headers = 0;
    }

    /* Now allow the crypto library to (potentially) insert some text
       (it may want to wrap the body in an envelope.)           */
    if (!m_parent) {
      status = m_state->BeginCryptoEncapsulation();
      if (status < 0) goto FAIL;
    }
          
    /* Now make sure there's a Content-Type header.
    */
    if (!content_type_header) 
    {
      NS_ASSERTION(m_type && *m_type, "null ptr");
      PRBool needsCharset = mime_type_needs_charset(m_type ? m_type : TEXT_PLAIN);
      if (needsCharset) 
      {
        content_type_header = PR_smprintf("Content-Type: %s; charset=%s" CRLF,
                                          (m_type ? m_type : TEXT_PLAIN), m_charset_name);
      }
      else
        content_type_header = PR_smprintf("Content-Type: %s" CRLF,
                                          (m_type ? m_type : TEXT_PLAIN));
      if (!content_type_header) 
      {
        if (content_headers)
          PR_Free(content_headers);
        status = NS_ERROR_OUT_OF_MEMORY;
        goto FAIL;
      }
    }
    
    /* If this is a compound object, tack a boundary string onto the
    Content-Type header. this
    */
    if (m_numchildren > 0)
    {
      int L;
      char *ct2;
      NS_ASSERTION(m_type, "null ptr");

      if (!separator)
      {
        separator = mime_make_separator("");
        if (!separator)
        {
          status = NS_ERROR_OUT_OF_MEMORY;
          goto FAIL;
        }
      }

      L = PL_strlen(content_type_header);
      
      if (content_type_header[L-1] == nsCRT::LF)
        content_type_header[--L] = 0;
      if (content_type_header[L-1] == nsCRT::CR)
        content_type_header[--L] = 0;
      
      ct2 = PR_smprintf("%s;\r\n boundary=\"%s\"" CRLF, content_type_header, separator);
      PR_Free(content_type_header);
      if (!ct2) 
      {
        if (content_headers)
          PR_Free(content_headers);
        status = NS_ERROR_OUT_OF_MEMORY;
        goto FAIL;
      }
      
      content_type_header = ct2;
    }
    
    // Now write out the Content-Type header...
    NS_ASSERTION(content_type_header && *content_type_header, "null ptr");
    PUSH(content_type_header);
    PR_Free(content_type_header);
    content_type_header = 0;
    
    /* ...followed by all of the other headers that refer to the body of
    the message (Content-Transfer-Encoding, Content-Dispositon, etc.)
    */
    if (content_headers) 
    {
      PUSH(content_headers);
      PR_Free(content_headers);
      content_headers = 0;
    }
  }

  PUSH(CRLF);         // A blank line, to mark the end of headers.

  m_firstBlock = PR_TRUE;
  /* only convert if we need to tag charset */
  m_needIntlConversion = mime_type_needs_charset(m_type);
  
  if (m_buffer) 
  {
    status = PushBody(m_buffer, PL_strlen(m_buffer));
    if (status < 0)
      goto FAIL;
  }
  else if (m_filespec) 
  {
    nsInputFileStream   myStream(*m_filespec);

    if (!myStream.is_open())
    {
      // mysteriously disappearing?
      nsCOMPtr<nsIMsgSendReport> sendReport;
      m_state->GetSendReport(getter_AddRefs(sendReport));
      if (sendReport)
      {
        nsAutoString error_msg;
        nsAutoString path;
        NS_CopyNativeToUnicode(
          nsDependentCString(m_filespec->GetNativePathCString()), path);
        nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
        sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
      }
      status = NS_MSG_UNABLE_TO_OPEN_TMP_FILE;
      goto FAIL;
    }
    /* Kludge to avoid having to allocate memory on the toy computers... */
    if (!mime_mailto_stream_read_buffer) 
    {
      mime_mailto_stream_read_buffer = (char *) PR_Malloc(MIME_BUFFER_SIZE);
      if (!mime_mailto_stream_read_buffer) 
      {
        status = NS_ERROR_OUT_OF_MEMORY;
        goto FAIL;
      }
    }

    char    *buffer = mime_mailto_stream_read_buffer;
    if (m_strip_sensitive_headers) 
    {
      // We are attaching a message, so we should be careful to
      // strip out certain sensitive internal header fields.
      PRBool skipping = PR_FALSE;

      while (1) 
      {
        char *line;

        if (myStream.eof())
          line = nsnull;
        else
        {
          buffer[0] = '\0';
          myStream.readline(buffer, MIME_BUFFER_SIZE-3);
          line = buffer;
        }
      
        if (!line)
          break;  /* EOF */
        
        if (skipping) {
          if (*line == ' ' || *line == '\t')
            continue;
          else
            skipping = PR_FALSE;
        }
        
        int hdrLen = PL_strlen(buffer);
        if ((hdrLen < 2) || (buffer[hdrLen-2] != nsCRT::CR)) { // if the line doesn't end with CRLF,
          // ... make it end with CRLF.
          if ( (hdrLen == 0) || ((buffer[hdrLen-1] != nsCRT::CR) && (buffer[hdrLen-1] != nsCRT::LF)) )
            hdrLen++;
          buffer[hdrLen-1] = '\015';
          buffer[hdrLen] = '\012';
          buffer[hdrLen+1] = '\0';
        }
        
        if (!PL_strncasecmp(line, "From -", 6) ||
            !PL_strncasecmp(line, "BCC:", 4) ||
            !PL_strncasecmp(line, "FCC:", 4) ||
            !PL_strncasecmp(line, CONTENT_LENGTH ":", CONTENT_LENGTH_LEN+1) ||
            !PL_strncasecmp(line, "Lines:", 6) ||
            !PL_strncasecmp(line, "Status:", 7) ||
            !PL_strncasecmp(line, X_MOZILLA_STATUS ":", X_MOZILLA_STATUS_LEN+1) ||
            !PL_strncasecmp(line, X_MOZILLA_STATUS2 ":", X_MOZILLA_STATUS2_LEN+1) ||
            !PL_strncasecmp(line, X_MOZILLA_DRAFT_INFO ":", X_MOZILLA_DRAFT_INFO_LEN+1) ||
            !PL_strncasecmp(line, X_MOZILLA_NEWSHOST ":", X_MOZILLA_NEWSHOST_LEN+1) ||
            !PL_strncasecmp(line, X_UIDL ":", X_UIDL_LEN+1) ||
            !PL_strncasecmp(line, "X-VM-", 5)) /* hi Kyle */
        {
          skipping = PR_TRUE;
          continue;
        }
        
        PUSH(line);
        
        if (*line == nsCRT::CR || *line == nsCRT::LF) {
          break;  // Now can do normal reads for the body.
        }
      }
    }
        
    while (!myStream.eof()) 
    {
      if ((status = myStream.read(buffer, MIME_BUFFER_SIZE)) < 0)
      {  
        nsCOMPtr<nsIMsgSendReport> sendReport;
        m_state->GetSendReport(getter_AddRefs(sendReport));
        if (sendReport)
        {
          nsAutoString error_msg;
          nsAutoString path;
          NS_CopyNativeToUnicode(nsDependentCString(m_filespec->GetNativePathCString()), path);
          nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_FILE, error_msg, &path, nsnull);
          sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
          status = NS_MSG_UNABLE_TO_OPEN_FILE;
          goto FAIL;
        }
      }
      status = PushBody(buffer, status);
      if (status < 0)
        goto FAIL;
    }
  }
  
  if (m_encoder_data) 
  {
    status = MIME_EncoderDestroy(m_encoder_data, PR_FALSE);
    m_encoder_data = nsnull;
    needToWriteCRLFAfterEncodedBody = !m_parent;
    if (status < 0)
      goto FAIL;
  }
  
  // 
  // Ok, from here we loop and drive the the output of all children 
  // for this message.
  //
  if (m_numchildren > 0) 
  {
    PRBool  writeSeparator = PR_TRUE;

    for (int i = 0 ; i < m_numchildren ; i ++) 
    {
      if (writeSeparator)
      {
        PUSH(CRLF);
        PUSH("--");

        PUSH(separator);
        PUSH(CRLF);
      }

      status = m_children[i]->Write();
      if (status < 0)
        goto FAIL;

      if (status == SKIP_EMPTY_PART)
        writeSeparator = PR_FALSE;
      else
        writeSeparator = PR_TRUE;
    }

    PUSH(CRLF);
    PUSH("--");
    PUSH(separator);
    PUSH("--");
    PUSH(CRLF);
  }
  else if (needToWriteCRLFAfterEncodedBody)
    PUSH(CRLF);
  
FAIL:
  PR_FREEIF(separator);
  return status;
}
Sequence::Sequence(
                        //CAMERASET
                          QString INPUT_PATH_CAMERA_SET_IN,

                        //MODEL
                          QString INPUT_BasePath_OutPut_IN,
                          QString INPUT_dynamicStringPart_IN,
                          QString INPUT_EXTENSSS_Mesh_IN,
                          QString INPUT_EXTENSSS_Skeleton_IN,
                          QString INPUT_EXTENSSS_Skin_IN,
                          QString INPUT_PATH_MODELS_INFO_IN,

                        //ANIMATION
                          QString PATH_OutputBase_IN,
                          QString PATH_FolderName_INPUT_IN,
                          QString INPUT_EXTENSSS_Motion_IN,
                          QString PATH_INDEX_BOUNDS_IN,

                        //SEQUENCE
                          QString PATH_INDEX_BOUNDS_INNN,
                          QString RadioSequenceID_String_IN,

                          bool printEnabled
                  )
{

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        cameraSet = CameraSet( INPUT_PATH_CAMERA_SET_IN );

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        Animation animSource = Animation(
                                              //MODEL
                                                INPUT_BasePath_OutPut_IN,
                                                INPUT_dynamicStringPart_IN,
                                                INPUT_EXTENSSS_Mesh_IN,
                                                INPUT_EXTENSSS_Skeleton_IN,
                                                INPUT_EXTENSSS_Skin_IN,
                                                INPUT_PATH_MODELS_INFO_IN,

                                              //ANIMATION
                                                PATH_OutputBase_IN,
                                                PATH_FolderName_INPUT_IN,
                                                INPUT_EXTENSSS_Motion_IN,
                                                PATH_INDEX_BOUNDS_IN,
                                                "Source_Animation",

                                                printEnabled
                                        );

        Animation animTarget = Animation(
                                              //MODEL
                                                INPUT_BasePath_OutPut_IN,
                                                INPUT_dynamicStringPart_IN,
                                                INPUT_EXTENSSS_Mesh_IN,
                                                INPUT_EXTENSSS_Skeleton_IN,
                                                INPUT_EXTENSSS_Skin_IN,
                                                INPUT_PATH_MODELS_INFO_IN,

                                              //ANIMATION
                                                PATH_OutputBase_IN,
                                                PATH_FolderName_INPUT_IN,
                                                INPUT_EXTENSSS_Motion_IN,
                                                PATH_INDEX_BOUNDS_IN,
                                                "Target_Animation",

                                                printEnabled
                                        );

        posedAnimations.append( animSource );
        posedAnimations.append( animTarget );

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        currentFrameNumber_Source = 0;
        currentFrameNumber_Target = 0;

        sequenceID_String = RadioSequenceID_String_IN;
        sequenceID        = sequenceID_String.toInt() - 1;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        QFile myFile ( PATH_INDEX_BOUNDS_INNN );

        myFile.open(QIODevice::ReadOnly);

        if( !myFile.isOpen() )
        {
            qDebug() << "\n\n\n   Sequence::Sequence - ERROR, unable to open **" << PATH_INDEX_BOUNDS_INNN << "** for IndexCheat Input \n\n\n";
            return;
        }

        QTextStream myStream(&myFile);

        QString dummyDescr;

        myStream >> dummyDescr;       myStream >> totalAllignedFrames;      posedAnimations[0].totalAllignedFrames = totalAllignedFrames;
        myStream >> dummyDescr;       myStream >> motionOffset;             posedAnimations[0].motionOffset        = motionOffset;

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /////////////////////////////////////////
        /////////////////////////////////////////
        if (printEnabled)   printAnimationINFO();
        /////////////////////////////////////////
        /////////////////////////////////////////

}
Exemplo n.º 15
0
void TestQgsWcsPublicServers::test( )
{
  QStringList versions;
  // It may happen that server supports 1.1.1, but does not accept 1.1 (http://zeus.pin.unifi.it/gi-wcs/http)
  versions << "" << "1.0.0" << "1.1.0"; // empty for default
  QStringList servers;
  // Some (first) coverages do not advertize any supportedCRS and sever gives
  // error both with native CRS (EPSG::561005) and EPSG:4326
  // MOD* coverages work OK
  servers << "http://argon.geogr.uni-jena.de:8080/geoserver/ows";
  servers << "http://demo.geonode.org/geoserver/wcs";
  servers << "http://demo.mapserver.org/cgi-bin/wcs";
  servers << "http://demo.opengeo.org/geoserver/wcs";
  // geobrain.laits.gmu.edu servers are quite slow
  servers << "http://geobrain.laits.gmu.edu/cgi-bin/gbwcs-dem";
  servers << "http://geobrain.laits.gmu.edu/cgi-bin/ows8/wcseo";
  servers << "http://geobrain.laits.gmu.edu/cgi-bin/wcs110";
  servers << "http://geobrain.laits.gmu.edu/cgi-bin/wcs-all";
  servers << "http://iceds.ge.ucl.ac.uk/cgi-bin/icedswcs";
  servers << "http://motherlode.ucar.edu:8080/thredds/wcs/fmrc/NCEP/DGEX/Alaska_12km/NCEP-DGEX-Alaska_12km_best.ncd";
  servers << "http://navigator.state.or.us/ArcGIS/services/Framework/Imagery_Mosaic2009/ImageServer/WCSServer";
  servers << "http://nsidc.org/cgi-bin/atlas_north";
  servers << "http://sedac.ciesin.columbia.edu/geoserver/wcs";
  // Big and slow
  //servers << "http://webmap.ornl.gov/ogcbroker/wcs";
  servers << "http://ws.csiss.gmu.edu/cgi-bin/wcs-t";
  // Big and slow
  //servers << "http://ws.laits.gmu.edu/cgi-bin/wcs-all";
  // Currently very slow or down
  //servers << "http://www.sogeo.ch/geoserver/wcs";
  // Slow and erroneous
  //servers << "http://zeus.pin.unifi.it/gi-wcs/http";

  foreach ( QString server, servers )
  {
    QStringList myServerLog;
    myServerLog << "server:" + server;
    QString myServerDirName = server;
    myServerDirName.replace( QRegExp( "[:/]+" ), "." );
    myServerDirName.replace( QRegExp( "\\.$" ), "" );
    QgsDebugMsg( "myServerDirName = " + myServerDirName );

    QDir myServerDir( mCacheDir.absolutePath() + QDir::separator() + myServerDirName );
    QString myServerLogPath = myServerDir.absolutePath() + QDir::separator() + "server.log";
    if ( QFileInfo( myServerLogPath ).exists() )
    {
      QgsDebugMsg( "cache exists " + myServerDir.absolutePath() );
      continue;
    }

    if ( !myServerDir.exists() )
    {
      mCacheDir.mkdir( myServerDirName );
    }

    foreach ( QString version, versions )
    {
      QgsDebugMsg( "server: " + server + " version: " + version );

      QgsDataSourceURI myServerUri;

      myServerUri.setParam( "url", server );
      if ( !version.isEmpty() )
      {
        myServerUri.setParam( "version", version );
      }

      QgsWcsCapabilities myCapabilities;
      myCapabilities.setUri( myServerUri );

      if ( !myCapabilities.lastError().isEmpty() )
      {
        QgsDebugMsg( myCapabilities.lastError() );
        myServerLog << "error: (version: " + version + ") " +  myCapabilities.lastError().replace( "\n", " " );
        continue;
      }

      QVector<QgsWcsCoverageSummary> myCoverages;
      if ( !myCapabilities.supportedCoverages( myCoverages ) )
      {
        QgsDebugMsg( "Cannot get list of coverages" );
        myServerLog << "error: (version: " + version + ") Cannot get list of coverages";
        continue;
      }

      int myCoverageCount = 0;
      int myStep = myCoverages.size() / mMaxCoverages;
      int myStepCount = -1;
      foreach ( QgsWcsCoverageSummary myCoverage, myCoverages )
      {
        QgsDebugMsg( "coverage: " + myCoverage.identifier );
        // Go in steps to get more success/errors
        if ( myStepCount == -1 || myStepCount > myStep )
        {
          myStepCount = 0;
        }
        else
        {
          myStepCount++;
          continue;
        }

        myCoverageCount++;
        if ( myCoverageCount > mMaxCoverages ) break;

        QString myPath = myServerDir.absolutePath() + QDir::separator() + myCoverage.identifier;

        if ( !version.isEmpty() )
        {
          myPath += "-" + version;
        }
        QString myLogPath = myPath + ".log";

        if ( QFileInfo( myLogPath ).exists() )
        {
          QMap<QString, QString> log = readLog( myLogPath );
          if ( !log.value( "identifier" ).isEmpty() && log.value( "error" ).isEmpty() ) continue;
        }

        QStringList myLog;
        myLog << "identifier:" + myCoverage.identifier;
        myCapabilities.describeCoverage( myCoverage.identifier );
        myCoverage = myCapabilities.coverage( myCoverage.identifier ); // get described
        QgsDataSourceURI myUri = myServerUri;
        myUri.setParam( "identifier", myCoverage.identifier );
        if ( myCoverage.times.size() > 0 )
        {
          myUri.setParam( "time", myCoverage.times.value( 0 ) );
        }
        myLog << "version:" + version;
        myLog << "uri:" + myUri.encodedUri();

        int myWidth = 100;
        int myHeight = 100;
        if ( myCoverage.hasSize )
        {
          myHeight = static_cast<int>( qRound( 1.0 * myWidth * myCoverage.height / myCoverage.width ) );
        }
        myLog << QString( "hasSize:%1" ).arg( myCoverage.hasSize );

        QgsRasterLayer * myLayer = new QgsRasterLayer( myUri.encodedUri(), myCoverage.identifier, "wcs", true );
        if ( myLayer->isValid() )
        {
          int myBandCount = myLayer->dataProvider()->bandCount();
          myLog << "bandCount:" + QString::number( myBandCount );
          if ( myBandCount > 0 )
          {
            myLog << "srcType:" + QString::number( myLayer->dataProvider()->srcDataType( 1 ) );

            QgsRasterBandStats myStats = myLayer->dataProvider()->bandStatistics( 1, QgsRasterBandStats::All, QgsRectangle(), myWidth * myHeight );
            myLog << "min:" + QString::number( myStats.minimumValue );
            myLog << "max:" + QString::number( myStats.maximumValue );
          }

          QgsMapRenderer myMapRenderer;
          QList<QgsMapLayer *> myLayersList;

          myLayersList.append( myLayer );
          QgsMapLayerRegistry::instance()->addMapLayers( myLayersList, false );

          QMap<QString, QgsMapLayer*> myLayersMap = QgsMapLayerRegistry::instance()->mapLayers();

          myMapRenderer.setLayerSet( myLayersMap.keys() );

          myMapRenderer.setExtent( myLayer->extent() );

          QImage myImage( myWidth, myHeight, QImage::Format_ARGB32_Premultiplied );
          myImage.fill( 0 );

          myMapRenderer.setOutputSize( QSize( myWidth, myHeight ), myImage.logicalDpiX() );

          QPainter myPainter( &myImage );
          myMapRenderer.render( &myPainter );

          // Save rendered image
          QString myPngPath = myPath + ".png";
          QgsDebugMsg( "myPngPath = " + myPngPath );
          myImage.save( myPngPath );

          // Verify data
          QSet<QString> myValues; // cannot be QSet<double>
          void *myData = myLayer->dataProvider()->readBlock( 1, myLayer->extent(), myWidth, myHeight );
          if ( myData )
          {
            int myType = myLayer->dataProvider()->dataType( 1 );
            for ( int row = 0; row < myHeight; row++ )
            {
              for ( int col = 0; col < myWidth; col++ )
              {
                double value = myLayer->dataProvider()->readValue( myData, myType, row * myWidth + col );
                QString valueStr = QString::number( value );
                if ( !myValues.contains( valueStr ) ) myValues.insert( valueStr );
              }
            }
            free( myData );
          }
          QgsDebugMsg( QString( "%1 values" ).arg( myValues.size() ) );
          myLog << QString( "valuesCount:%1" ).arg( myValues.size() );

          // Verify image colors
          QSet<QRgb> myColors;
          for ( int row = 0; row < myHeight; row++ )
          {
            for ( int col = 0; col < myWidth; col++ )
            {
              QRgb color = myImage.pixel( col, row );
              if ( !myColors.contains( color ) ) myColors.insert( color );
            }
          }
          QgsDebugMsg( QString( "%1 colors" ).arg( myColors.size() ) );
          myLog << QString( "colorsCount:%1" ).arg( myColors.size() );
        }
        else
        {
          QgsDebugMsg( "Layer is not valid" );
          myLog << "error:Layer is not valid";
        }

        QFile myLogFile( myLogPath );
        myLogFile.open( QIODevice::WriteOnly | QIODevice::Text );
        QTextStream myStream( &myLogFile );
        myStream << myLog.join( "\n" );

        myLogFile.close();
        QgsMapLayerRegistry::instance()->removeAllMapLayers();
      }
void Model::readMesh_OFF( QString myFileString_Mesh )
{

     QFile myFileIN( myFileString_Mesh );
     myFileIN.open(QIODevice::ReadOnly);

     if(!myFileIN.isOpen())
     {
         qDebug() << "Animation::OFF_Exporter_model->mesh - Error, unable to open" << myFileString_Mesh << "for output";
         return;
     }

     QTextStream myStream(&myFileIN);

     ////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////

     QString dummyString;
     int     dummyInt;

     myStream >> dummyString;
     myStream >> totalVertices;
     myStream >> totalTriangles;
     myStream >> dummyInt;

     ////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////

     mesh.vertices.clear();              mesh.vertices.resize(            totalVertices);
     mesh.verticesOLD.clear();           mesh.verticesOLD.resize(         totalVertices);
     mesh.verticesWeighted.clear();      mesh.verticesWeighted.resize(    totalVertices);
     mesh.normals_Vertices.clear();      mesh.normals_Vertices.resize(    totalVertices);
     mesh.triangles.clear();             mesh.triangles.resize(           totalTriangles);


     for (int vvv=0; vvv<totalVertices; vvv++)
     {
         mesh.vertices[        vvv] = Eigen::Vector3d::Zero();
         mesh.verticesOLD[     vvv] = Eigen::Vector3d::Zero();
         mesh.verticesWeighted[vvv] = Eigen::Vector3d::Zero();
     }

     ////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////

     for (int vvv=0; vvv<totalVertices; vvv++)
     {
             myStream >> mesh.vertices[vvv](0);
             myStream >> mesh.vertices[vvv](1);
             myStream >> mesh.vertices[vvv](2);
     }

     ////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////

     for (int tr=0; tr<totalTriangles; tr++)
     {
             myStream >> dummyInt;
             myStream >> mesh.triangles[tr].vertexID_1;
             myStream >> mesh.triangles[tr].vertexID_2;
             myStream >> mesh.triangles[tr].vertexID_3;
     }

     ////////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////

     myFileIN.close();

}
Exemplo n.º 17
0
const QString OmgGdal::Gdal2Ascii(const QString theFileName)
{
  std::cout << "Running gdal to ascii conversion..." << std::endl;
  QFileInfo myFileInfo(theFileName);
  QString myExt("asc");
  QString myOutFileName(QDir::convertSeparators(myFileInfo.dirPath(true)+"/"+myFileInfo.baseName() + "." + myExt));
  QFile myFile( myOutFileName );
  if ( !myFile.open( IO_WriteOnly ) )
  {
    printf("Opening output file for write failed");
    return QString("");
  }
  QTextStream myStream( &myFile );
  GDALAllRegister();
  GDALDataset  *gdalDataset = (GDALDataset *) GDALOpen( theFileName.local8Bit(), GA_ReadOnly );
  if ( gdalDataset == NULL )
  {
    std::cout <<  "Error couldn't open file: " << theFileName << std::endl;
    return QString("");
  }

  //Write the ascii headers
  myStream << getAsciiHeader(theFileName);

  //assume to be working with first band in dataset only
  GDALRasterBand  *myGdalBand = gdalDataset->GetRasterBand( 1 );
  //find out the name of the band if any
  QString myColorInterpretation = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
  // get the dimensions of the raster
  int myColsInt = myGdalBand->GetXSize();
  int myRowsInt = myGdalBand->GetYSize();
  double myNullValue=myGdalBand->GetNoDataValue();
  //allocate a buffer to hold one row of ints
  int myAllocationSizeInt = sizeof(uint)*myColsInt;
  uint * myScanlineAllocInt = (uint*) CPLMalloc(myAllocationSizeInt);
  for (int myCurrentRowInt=0; myCurrentRowInt < myRowsInt;myCurrentRowInt++)
  {
    //get a scanline
    CPLErr myResult = myGdalBand->RasterIO(
                        GF_Read, 0,
                        myCurrentRowInt,
                        myColsInt,
                        1,
                        myScanlineAllocInt,
                        myColsInt,
                        1,
                        GDT_UInt32,
                        0,
                        0 );
    for (int myCurrentColInt=0; myCurrentColInt < myColsInt; myCurrentColInt++)
    {
      //get the nth element from the current row
      double myDouble=myScanlineAllocInt[myCurrentColInt];
      myStream << myDouble << " "; //pixel value
    } //end of column wise loop
    myStream << "\r\n"; //dos style new line
  } //end of row wise loop
  CPLFree(myScanlineAllocInt);
  myFile.close();
  std::cout << "The output ascii file is: " << myOutFileName << std::endl;
  return myOutFileName;
}