예제 #1
0
//从文件加载数据
bool  CDataManageCenter::LoadDataFromFile(CString FilePath,bool IsChuHaoXunXu,bool IsClean)
{
	if(!IsChuHaoXunXu)
	{
		if(IsClean)
			m_ShuangSeQiuList.clear();

		LoadDataFromFile(FilePath,m_ShuangSeQiuList);

		//保存统计数据到csv文件中
	//	SaveDataToCSVFile();

		//保存统计五期以内和五期以外数据到txt文件中
		SaveFiveDataToTxtFile();
	}
	else
	{
		if(IsClean)
			m_ShuangSeQiuChuHaoList.clear();

		LoadDataFromFile(FilePath,m_ShuangSeQiuChuHaoList);

	}
	return true;
}
예제 #2
0
파일: Renderer.cpp 프로젝트: TACC/VolViewer
void
Renderer::LoadVolume(std::string volumeName)
{
	LoadDataFromFile(volumeName);

	int x, y, z;
  volume.GetDimensions(x, y, z);

  int m = x > y ? x > z ? x : z : y > z ? y : z;

  osp::vec3f eye((x-1)/2.0, (y-1)/2.0, -(3*m - (z-1)/2.0));
  osp::vec3f center((x-1)/2.0, (y-1)/2.0, (z-1)/2.0);
  osp::vec3f up(0.0, 1.0, 0.0);

  getCamera().setupFrame(eye, center, up);
  getCamera().commit();

	getLights().commit(getRenderer());
	getTransferFunction().commit(getRenderer());
	getTransferFunction().showColors();
	getSlices().commit(getRenderer(), &volume);
	getIsos().commit(&volume);
	renderProperties.commit();
	
}
예제 #3
0
bool CBillBoard::Init(char* BillBoardFile,char* AddName)
{
	LoadDataFromFile(BillBoardFile,AddName);
	BILL_VERT vert[] =
	{
		{-1.0f, 1.0f,0.0f,0x77ffffff,0.0f * m_iScalU,0.0f * m_iScalV},
		{ 1.0f, 1.0f,0.0f,0x77ffffff,1.0f * m_iScalU,0.0f * m_iScalV},
		{-1.0f,-1.0f,0.0f,0x77ffffff,0.0f * m_iScalU,1.0f * m_iScalV},
		{ 1.0f,-1.0f,0.0f,0x77ffffff,1.0f * m_iScalU,1.0f * m_iScalV},
	};				  
	// 公告板顶点	  
	if (FAILED(m_pDevice->CreateVertexBuffer(sizeof(vert),D3DUSAGE_WRITEONLY,BILL_FVF,
												D3DPOOL_DEFAULT,&m_pVB,0)))
	{
		return false;
	}
	void* pvert;
	m_pVB->Lock(0,sizeof(vert),(void**)&pvert,0);
	memcpy(pvert,vert,sizeof(vert));
	m_pVB->Unlock();
	// 读取公告板纹理
	LoadTexture(m_TexturePath,m_iTextureNum);
	iter = m_vecTexture.begin();
	return true;
}
예제 #4
0
bool TessdataManager::CombineDataFiles(
    const char *language_data_path_prefix,
    const char *output_filename) {
  // Load individual tessdata components from files.
  for (int i = 0; i < TESSDATA_NUM_ENTRIES; ++i) {
    TessdataType type;
    ASSERT_HOST(TessdataTypeFromFileSuffix(kTessdataFileSuffixes[i], &type));
    STRING filename = language_data_path_prefix;
    filename += kTessdataFileSuffixes[i];
    FILE *fp = fopen(filename.string(), "rb");
    if (fp != nullptr) {
      fclose(fp);
      if (!LoadDataFromFile(filename, &entries_[type])) {
        tprintf("Load of file %s failed!\n", filename.string());
        return false;
      }
    }
  }
  is_loaded_ = true;

  // Make sure that the required components are present.
  if (!IsBaseAvailable() && !IsLSTMAvailable()) {
    tprintf(
        "Error: traineddata file must contain at least (a unicharset file"
        "and inttemp) OR an lstm file.\n");
    return false;
  }
  // Write updated data to the output traineddata file.
  return SaveFile(output_filename, nullptr);
}
vector<string> SetupModel(string categoryName, vector<Mat> &trainData, vector<Mat> &trainLabels, 
						  vector<float> &videoFPS, int database_type)
{
	cout << "Loading training data..." << endl << endl;

	//Get data stored in database
	string path;
	if (database_type == 1)
		path = "Data/Training_Data/" + categoryName + "/BOW/";
	else
		path = "Data/Training_Data/" + categoryName + "/MPEG7/";

	vector<string> _listTrainingData = ReadFileList(path);

	for (int i = 0; i < (int)_listTrainingData.size(); i++)
	{
		string pathData = path + _listTrainingData[i];
		Mat trainingData, trainingLabel;
		float fps;
		LoadDataFromFile(pathData, trainingData, trainingLabel, fps);

		trainData.push_back(trainingData);
		trainLabels.push_back(trainingLabel);
		videoFPS.push_back(fps);
	}

	return _listTrainingData;
}
예제 #6
0
bool TessdataManager::Init(const char *data_file_name) {
  GenericVector<char> data;
  if (reader_ == nullptr) {
    if (!LoadDataFromFile(data_file_name, &data)) return false;
  } else {
    if (!(*reader_)(data_file_name, &data)) return false;
  }
  return LoadMemBuffer(data_file_name, &data[0], data.size());
}
예제 #7
0
WidgetToolBar::WidgetToolBar(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::WidgetToolBar)
{
    ui->setupUi(this);
    LoadDataFromFile();

    connect(ui->spinDovolena,SIGNAL(valueChanged(int)),
            this,SIGNAL(DovolenaChanged(int)));
}
NodeBasedGraphFactory::NodeBasedGraphFactory(
    const boost::filesystem::path &input_file,
    ScriptingEnvironment &scripting_environment,
    std::vector<TurnRestriction> &turn_restrictions,
    std::vector<ConditionalTurnRestriction> &conditional_turn_restrictions)
{
    LoadDataFromFile(input_file);
    Compress(scripting_environment, turn_restrictions, conditional_turn_restrictions);
    CompressGeometry();
    CompressAnnotationData();
}
예제 #9
0
bool TFile::Open(const STRING& filename, FileReader reader) {
  if (!data_is_owned_) {
    data_ = new GenericVector<char>;
    data_is_owned_ = true;
  }
  offset_ = 0;
  is_writing_ = false;
  if (reader == NULL)
    return LoadDataFromFile(filename, data_);
  else
    return (*reader)(filename, data_);
}
예제 #10
0
bool TessdataManager::OverwriteComponents(
    const char *new_traineddata_filename,
    char **component_filenames,
    int num_new_components) {
  // Open the files with the new components.
  for (int i = 0; i < num_new_components; ++i) {
    TessdataType type;
    if (TessdataTypeFromFileName(component_filenames[i], &type)) {
      if (!LoadDataFromFile(component_filenames[i], &entries_[type])) {
        tprintf("Failed to read component file:%s\n", component_filenames[i]);
        return false;
      }
    }
  }

  // Write updated data to the output traineddata file.
  return SaveFile(new_traineddata_filename, nullptr);
}
예제 #11
0
void
CTest5Section::Reaction( long in_SrcSectionID, const CRenderSection_InitRenderResult& in_rResult )
{
	CLog::Print("CTest5Section::Reaction( const CRenderSection_InitRenderResult& in_rResult )\n");
	CLog::Print("  init %s\n", (in_rResult.m_Result==IRR_OK)? "SUCCEEDED":"FAILED" );
	assert(in_rResult.m_Result==IRR_OK);

	// create VB
//	CVBFormat VBFormat;
//	VBFormat.m_XYZ = true;
//	VBFormat.m_Diffuse = true;
//	CRenderSection_CreateVertexBuffer_Request Cmd( VBFormat, false );
//	Cmd.m_Data.resize( 6*sizeof(CCustomVertex) );
//	memcpy( (unsigned char*)&(Cmd.m_Data[0]), vertices, 6*sizeof(CCustomVertex) );
//	CTCommandSender<CRenderSection_CreateVertexBuffer_Request>::SendCommand(
//		m_RenderSectionID,
//		Cmd
//	);
	CVBFormat VBFormat;
	std::vector<unsigned char> Data;
	m_PrimitiveType = 0;
	bool Success = LoadDataFromFile("cube.txt",VBFormat,Data,m_PrimitiveType,m_NVertices);
	assert(Success);
CLog::Print("  m_PrimitiveType=%lu\n",m_PrimitiveType);
CLog::Print("  m_NVertices=%lu\n",m_NVertices);
	m_NPrimitives = CalcNPrimitives(m_PrimitiveType,m_NVertices);
CLog::Print("  m_NPrimitives=%lu\n",m_NPrimitives);
	CRenderSection_CreateVertexBuffer_Request Cmd( VBFormat, false );
	Cmd.m_Data = Data;
	CTCommandSender<CRenderSection_CreateVertexBuffer_Request>::SendCommand(
		m_RenderSectionID,
		Cmd
	);

	CLog::Print("CTest5Section::Reaction( const CRenderSection_InitRenderResult& in_rResult ) end\n");
}
예제 #12
0
파일: Renderer.cpp 프로젝트: TACC/VolViewer
void
Renderer::LoadState(std::string statefile, bool with_data)
{
  Document doc;

  std::ifstream in;
  in.open(statefile.c_str(), std::istream::in);
  in.seekg(0, std::ios::end);
  std::streamsize size = in.tellg();
  in.seekg(0, std::ios::beg);

  in.read(xyzzy, size);
  doc.Parse(xyzzy);
  in.close();

	if (! doc.IsObject() ||  ! doc.HasMember("State"))
  {
    std::cerr << "invalud state file\n";
    return;
  }

	if (doc["State"].HasMember("Camera")) 
	{
		getCamera().loadState(doc["State"]["Camera"]);
		getCamera().commit();
	}

	if (doc["State"].HasMember("Lights")) 
	{
		getLights().loadState(doc["State"]["Lights"]);
		getLights().commit(getRenderer());
	}

	if (doc["State"].HasMember("TransferFunction")) 
	{
		getTransferFunction().loadState(doc["State"]["TransferFunction"]);
		if (doc["State"]["TransferFunction"].HasMember("Colormap"))
		{
			getColorMap().loadState(doc["State"]["TransferFunction"]["Colormap"]);
			getColorMap().commit(getTransferFunction());
		}
		getTransferFunction().commit(getRenderer());
	}

	if (doc["State"].HasMember("Slices")) 
	{
		getSlices().loadState(doc["State"]["Slices"]);
		getSlices().commit(getRenderer(), &volume);
	}
	
	if (doc["State"].HasMember("Isosurfaces")) 
	{
		getIsos().loadState(doc["State"]["Isosurfaces"]);
		getIsos().commit(&volume);
	}

	if (with_data)
		LoadDataFromFile(doc["State"]["Volume"].GetString());
	
	in.close();
}
예제 #13
0
int convert(char *inFile, char *outFile)    
{
    sint32 retVal = 0;

    uint32 versionMajor = 0;
    uint32 versionMinor = 0;

    unsigned char *pInputBuffer = NULL;
    unsigned char *pOutputBuffer = NULL;
    uint32 lenInput = 0;
    uint32 lenOutput = 0;

    retVal = BCGetVersion( &versionMajor, &versionMinor );
    // Get library version and print it
    printf( "\nBiodata Conversion Library version %d.%d convert template sample\n",
        versionMajor, versionMinor );

    // Check command line parameters count
    

        // Read template from file

        retVal = LoadDataFromFile( inFile, &pInputBuffer, &lenInput );
        if ( retVal < 0 )
        {
            printf( "Error reading file '%s' (code %d)\n", inFile, retVal );
        }
        else
        {
            // Get output data langth
    
            retVal = BCConvertTemplate( BCTE_NONE, BCT_ISO_FMR, 
                pInputBuffer, lenInput,
                BCTE_PT_BIR, BCT_UPEK_LEGACY,
                NULL, &lenOutput,
                NULL );

            if ( retVal != BCERR_OK )
            {
                // Cannot get output lenght, report error
                
                printf( "Error getting output length (code %d)\n",
                    retVal );
            }
            else
            {
                // Allocate memory 

                pOutputBuffer = (unsigned char *) malloc( lenOutput );

                // Call conversion
    
                retVal = BCConvertTemplate( BCTE_NONE, BCT_ISO_FMR, 
                    pInputBuffer, lenInput,
                    BCTE_PT_BIR, BCT_UPEK_LEGACY,
                    pOutputBuffer, &lenOutput,
                    NULL );
            
                if ( retVal == BCERR_OK )
                {
                    // Success, store data to file
                
                    StoreDataToFile( outFile, pOutputBuffer, lenOutput );
                    printf( "File '%s' converted to '%s'\n",
                        inFile, outFile );
                }
                else
                {
                    // Conversion failed, report error
                
                    printf( "Error converting file '%s' (code %d)\n",
                        inFile, retVal );
                }
            }
        }

    // Cleanup
    
    if ( pInputBuffer != NULL )
    {
        free( pInputBuffer );
    }

    if ( pOutputBuffer != NULL )
    {
        free( pOutputBuffer );
    }

    return retVal;
}
예제 #14
0
	bool LoadTextFile(buffer& buff, const TCHAR* filename)
	{
		return LoadDataFromFile(buff, filename, true);
	}
예제 #15
0
	bool LoadBinaryFile(buffer& buff, const TCHAR* filename)
	{
		return LoadDataFromFile(buff, filename, false);
	}
예제 #16
0
nsresult
nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg)
{
  NS_ASSERTION(m_mime_delivery_state != nsnull, "not-null m_mime_delivery_state");

  // Close the file, but don't delete the disk file (or the file spec.)
  if (mOutFile)
  {
    mOutFile->Close();
    mOutFile = nsnull;
  }
  // this silliness is because Windows nsILocalFile caches its file size
  // so if an output stream writes to it, it will still return the original
  // cached size.
  if (mTmpFile)
  {
    nsCOMPtr <nsIFile> tmpFile;
    mTmpFile->Clone(getter_AddRefs(tmpFile));
    mTmpFile = do_QueryInterface(tmpFile);
  }
  mRequest = nsnull;

  // First things first, we are now going to see if this is an HTML
  // Doc and if it is, we need to see if we can determine the charset
  // for this part by sniffing the HTML file.
  // This is needed only when the charset is not set already.
  // (e.g. a charset may be specified in HTTP header)
  //
  if (!m_type.IsEmpty() && m_charset.IsEmpty() &&
      m_type.LowerCaseEqualsLiteral(TEXT_HTML))
    m_charset = nsMsgI18NParseMetaCharset(mTmpFile);

  nsresult mimeDeliveryStatus;
  m_mime_delivery_state->GetStatus(&mimeDeliveryStatus);

  if (mimeDeliveryStatus == NS_ERROR_ABORT)
    status = NS_ERROR_ABORT;

  if (NS_FAILED(status) && status != NS_ERROR_ABORT && NS_SUCCEEDED(mimeDeliveryStatus))
  {
    // At this point, we should probably ask a question to the user
    // if we should continue without this attachment.
    //
    bool              keepOnGoing = true;
    nsCString    turl;
    nsString     msg;
    PRUnichar         *printfString = nsnull;
    nsresult rv;
    nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv));
    NS_ENSURE_SUCCESS(rv, rv);
    nsCOMPtr<nsIStringBundle> bundle;
    rv = bundleService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(bundle));
    NS_ENSURE_SUCCESS(rv, rv);
    nsMsgDeliverMode mode = nsIMsgSend::nsMsgDeliverNow;
    m_mime_delivery_state->GetDeliveryMode(&mode);
    if (mode == nsIMsgSend::nsMsgSaveAsDraft || mode == nsIMsgSend::nsMsgSaveAsTemplate)
      bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SAVING, getter_Copies(msg));
    else
      bundle->GetStringFromID(NS_MSG_FAILURE_ON_OBJ_EMBED_WHILE_SENDING, getter_Copies(msg));
    if (!m_realName.IsEmpty())
      printfString = nsTextFormatter::smprintf(msg.get(), m_realName.get());
    else if (NS_SUCCEEDED(mURL->GetSpec(turl)) && !turl.IsEmpty())
    {
      nsCAutoString unescapedUrl;
      MsgUnescapeString(turl, 0, unescapedUrl);
      if (unescapedUrl.IsEmpty())
        printfString = nsTextFormatter::smprintf(msg.get(), turl.get());
      else
        printfString = nsTextFormatter::smprintf(msg.get(), unescapedUrl.get());
    }
    else
      printfString = nsTextFormatter::smprintf(msg.get(), "?");

    nsCOMPtr<nsIPrompt> aPrompt;
    if (m_mime_delivery_state)
      m_mime_delivery_state->GetDefaultPrompt(getter_AddRefs(aPrompt));
    nsMsgAskBooleanQuestionByString(aPrompt, printfString, &keepOnGoing);
    PR_FREEIF(printfString);

    if (keepOnGoing)
    {
      status = 0;
      m_bogus_attachment = true; //That will cause this attachment to be ignored.
    }
    else
    {
      status = NS_ERROR_ABORT;
      m_mime_delivery_state->SetStatus(status);
      nsresult ignoreMe;
      m_mime_delivery_state->Fail(status, nsnull, &ignoreMe);
      m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull);
      SetMimeDeliveryState(nsnull);
      return status;
    }
  }

  m_done = true;

  //
  // Ok, now that we have the file here on disk, we need to see if there was
  // a need to do conversion to plain text...if so, the magic happens here,
  // otherwise, just move on to other attachments...
  //
  if (NS_SUCCEEDED(status) && !m_type.LowerCaseEqualsLiteral(TEXT_PLAIN) &&
      m_desiredType.LowerCaseEqualsLiteral(TEXT_PLAIN))
  {
    //
    // Conversion to plain text desired.
    //
    PRInt32       width = 72;
    nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
    if (pPrefBranch)
      pPrefBranch->GetIntPref("mailnews.wraplength", &width);
    // Let sanity reign!
    if (width == 0)
      width = 72;
    else if (width < 10)
      width = 10;
    else if (width > 30000)
      width = 30000;

    //
    // Now use the converter service here to do the right
    // thing and convert this data to plain text for us!
    //
    nsAutoString      conData;

    if (NS_SUCCEEDED(LoadDataFromFile(mTmpFile, conData, true)))
    {
      if (NS_SUCCEEDED(ConvertBufToPlainText(conData, UseFormatFlowed(m_charset.get()))))
      {
        if (mDeleteFile)
          mTmpFile->Remove(false);

        nsCOMPtr<nsIOutputStream> outputStream;
        nsresult rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mTmpFile,  PR_WRONLY | PR_CREATE_FILE, 00600);

        if (NS_SUCCEEDED(rv))
        {
          nsCAutoString tData;
          if (NS_FAILED(ConvertFromUnicode(m_charset.get(), conData, tData)))
            LossyCopyUTF16toASCII(conData, tData);
          if (!tData.IsEmpty())
          {
            PRUint32 bytesWritten;
            (void) outputStream->Write(tData.get(), tData.Length(), &bytesWritten);
          }
          outputStream->Close();
          // this silliness is because Windows nsILocalFile caches its file size
          // so if an output stream writes to it, it will still return the original
          // cached size.
          if (mTmpFile)
          {
            nsCOMPtr <nsIFile> tmpFile;
            mTmpFile->Clone(getter_AddRefs(tmpFile));
            mTmpFile = do_QueryInterface(tmpFile);
          }

        }
      }
    }

    m_type = m_desiredType;
    m_desiredType.Truncate();
    m_encoding.Truncate();
  }

  PRUint32 pendingAttachmentCount = 0;
  m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
  NS_ASSERTION (pendingAttachmentCount > 0, "no more pending attachment");

  m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1);

  bool processAttachmentsSynchronously = false;
  m_mime_delivery_state->GetProcessAttachmentsSynchronously(&processAttachmentsSynchronously);
  if (NS_SUCCEEDED(status) && processAttachmentsSynchronously)
  {
    /* Find the next attachment which has not yet been loaded,
     if any, and start it going.
     */
    PRUint32 i;
    nsMsgAttachmentHandler *next = 0;
    nsMsgAttachmentHandler *attachments = nsnull;
    PRUint32 attachmentCount = 0;

    m_mime_delivery_state->GetAttachmentCount(&attachmentCount);
    if (attachmentCount)
      m_mime_delivery_state->GetAttachmentHandlers(&attachments);

    for (i = 0; i < attachmentCount; i++)
    {
      if (!attachments[i].m_done)
      {
        next = &attachments[i];
        //
        // rhp: We need to get a little more understanding to failed URL
        // requests. So, at this point if most of next is NULL, then we
        // should just mark it fetched and move on! We probably ignored
        // this earlier on in the send process.
        //
        if ( (!next->mURL) && (next->m_uri.IsEmpty()) )
        {
          attachments[i].m_done = true;
          m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
          m_mime_delivery_state->SetPendingAttachmentCount(pendingAttachmentCount - 1);
          next->mPartUserOmissionOverride = true;
          next = nsnull;
          continue;
        }

        break;
      }
    }

    if (next)
    {
      int status = next->SnarfAttachment(mCompFields);
      if (NS_FAILED(status))
      {
        nsresult ignoreMe;
        m_mime_delivery_state->Fail(status, nsnull, &ignoreMe);
        m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, 0, nsnull);
        SetMimeDeliveryState(nsnull);
        return NS_ERROR_UNEXPECTED;
      }
    }
  }

  m_mime_delivery_state->GetPendingAttachmentCount(&pendingAttachmentCount);
  if (pendingAttachmentCount == 0)
  {
    // If this is the last attachment, then either complete the
    // delivery (if successful) or report the error by calling
    // the exit routine and terminating the delivery.
    if (NS_FAILED(status))
    {
      nsresult ignoreMe;
      m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
      m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull);
      SetMimeDeliveryState(nsnull);
      return NS_ERROR_UNEXPECTED;
    }
    else
    {
      status = m_mime_delivery_state->GatherMimeAttachments ();
      if (NS_FAILED(status))
      {
        nsresult ignoreMe;
        m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
        m_mime_delivery_state->NotifyListenerOnStopSending(nsnull, status, aMsg, nsnull);
        SetMimeDeliveryState(nsnull);
        return NS_ERROR_UNEXPECTED;
      }
    }
  }
  else
  {
    // If this is not the last attachment, but it got an error,
    // then report that error and continue
    if (NS_FAILED(status))
    {
      nsresult ignoreMe;
      m_mime_delivery_state->Fail(status, aMsg, &ignoreMe);
    }
  }

  SetMimeDeliveryState(nsnull);
  return NS_OK;
}
예제 #17
0
RegionFileLoader::RegionFileLoader(std::ifstream &ifile)
    : fTheRegions()
{
    LoadDataFromFile(ifile);
}