Пример #1
0
/*
 * Separating the uri, for example: http://10.0.1.1:8080/path1/path2
 */
int separateUri(char *uri, char *ip, char *port, char *path)
{
	if (NULL == uri || NULL == ip || NULL == port || NULL == path)
	{
		return -1;
	}

	/* take ip */
	if (0 > cutString(uri+strlen("http://"), NULL, ":", ip))
	{
		return -1;
	}

	/* take port */
	if (0 > cutString(uri+strlen("http://")+strlen(ip)+strlen(":"), NULL, "/", port))
	{
		return -1;
	}

	/* take path */
	if (0 > cutString(uri+strlen("http://")+strlen(ip)+strlen(":")+strlen(port)+strlen("/"), NULL, NULL, path))
	{
		return -1;
	}

	return 0;
}
Пример #2
0
void singlePeCalMin() {

    vector<inputValues>  b; // Blank runs
    vector<inputValues>  t; // Total runs
    vector<outputValues> o;
    vector<string> cutString(cut_b.size(), "Min > ");

    // Create strings to perform cuts 
    for (int i = 0; i < cut_b.size(); i++) { cutString[i].append(to_string(cut_b[i])); }

    // Get input and output values from .root spectra
    for (int i = 0; i < fileNames_b.size(); i++) {
        b.push_back(getInputValues(fileNames_b[i], pulseWidths_b[i], cutString[i]));

        for (int j = 0; j < fileNames_t.size(); j++) {
            t.push_back(getInputValues(fileNames_t[j], pulseWidths_t[j], cutString[i]));
            o.push_back(getOutputValues(b[i], t[j]));
        }
    }
    makePlots(b, t, o, cut_b[0]);

    // Debugging
    cout << "BG E[T}: " << b[0].e << "  BG a/n: " << b[0].a / b[0].n << endl;
    cout << setw(12) << "a/n  " << setw(12) << "E[L]  " << setw(12) 
         << "E[Psi]" << setw(12) << "E[T]" << endl;
    for ( int i = 0; i < t.size(); i++) {
        cout << setw(12) << (float)t[i].a / t[i].n << setw(12) << o[i].eL << setw(12)
             << o[i].ePsi << setw(12) << t[i].e << endl;
    }
}
void singlePeVaryMode() {

    vector<inputValues> b; // Blank runs
    vector<inputValues> t; // Total runs
    vector<outputValues> o;
    vector<string> cutString(cut_b.size(), "Charge > ");
    
    // Create strings to perform cuts - I would be able to use to_string if C++11 worked 
    for (int i = 0; i < cut_b.size(); i++) {
        ostringstream ss;
        ss << cut_b[i];
        cutString[i].append(ss.str());
    }
    
    // Get input and output values from .root spectra
    for (int i = 0; i < fileNames_b.size(); i++) {
        b.push_back(getInputValues(fileNames_b[i], pulseWidths_b[i], useChargeMode_b[i], cutString[i]));
        
        for (int j = 0; j < fileNames_t.size(); j++) {
            if (useChargeMode_t[j] == useChargeMode_b[i]) {
                t.push_back(getInputValues(fileNames_t[j], pulseWidths_t[j], useChargeMode_t[j], cutString[i]));
                o.push_back(getOutputValues(b[i], t[j]));
            }
        }
    }
    makePlots(b, t, o);
}
Пример #4
0
int main (int argc, char *argv[]){
  int i ;
  char **s ;
  i = 0 ;
  s = cutString(' ', argv[1]) ;
  while (s[i++]!=NULL){
    printf("%s\n", s[i]) ;
  }
  return EXIT_SUCCESS ;
}
Пример #5
0
void liqRibData::parseVectorAttributes( MFnDependencyNode & nodeFn, MStringArray & strArray, ParameterType pType )
{
  MStatus status;
  if ( strArray.length() > 0 ) 
  {
    for ( unsigned i( 0 ); i < strArray.length(); i++ ) 
    {
      liqTokenPointer tokenPointerPair;
      MString cutString( strArray[i].substring(5, strArray[i].length() ) );
      MPlug vPlug( nodeFn.findPlug( strArray[i] ) );
      MObject plugObj;
      status = vPlug.getValue( plugObj );
      if ( plugObj.apiType() == MFn::kVectorArrayData ) 
      {
        MFnVectorArrayData  fnVectorArrayData( plugObj );
        MVectorArray vectorArrayData = fnVectorArrayData.array( &status );
        tokenPointerPair.set(   cutString.asChar(),
                                pType,
                                true,
                                false,
                                vectorArrayData.length() );
        for ( unsigned kk( 0 ); kk < vectorArrayData.length(); kk++ ) 
          tokenPointerPair.setTokenFloat( kk, vectorArrayData[kk].x, vectorArrayData[kk].y, vectorArrayData[kk].z );

        // should it be per vertex or face-varying
        if ( ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) && 
						 ( vectorArrayData.length() == faceVaryingCount ) ) 
          tokenPointerPair.setDetailType( rFaceVarying);
        else 
          tokenPointerPair.setDetailType( rVertex );
        // store it all
        tokenPointerArray.push_back( tokenPointerPair );

      } 
      else 
      {
        // Hmmmm float ? double ?
        float x, y, z;
        tokenPointerPair.set( cutString.asChar(), pType );

        vPlug.child(0).getValue( x );
        vPlug.child(1).getValue( y );
        vPlug.child(2).getValue( z );
        tokenPointerPair.setTokenFloat( 0, x, y, z );
        tokenPointerPair.setDetailType( rConstant );
        tokenPointerArray.push_back( tokenPointerPair );
      }
    }
  }
}
Пример #6
0
int PPMCompressor::CompressFile(BitFile &inputFile, BitFile &outputFile, bool paramVerbose) {
	int result;
	unsigned char curSymbol;
	int curOrder,i;
	std::string context;
	ContextModel *CM;
	Intervals curInterval;
	RangeCoder RC;
	unsigned int mask[256];

	unsigned int cumFreq;

	long int fSize, kSymb;

	FILE *f = tmpfile();
	RC.StartEncode(f);

	CM = new ContextModel[ORDER+1];
	for (i = 0; i <= ORDER; ++i) {
		CM[i].SetOrder(i);
	}

	context = "";


	fSize = inputFile.GetFileSize();
	kSymb = 0;
	if (paramVerbose)  printProcentsBar(kSymb,fSize);


	do {
		inputFile.Read(&curSymbol,sizeof(char));




		if ( !inputFile.FEOF() ) {


			if (paramVerbose) printProcentsBar(++kSymb,fSize);

			curOrder = ORDER;
			for (i = 0; i < 256; ++i) {
				mask[i] = 0;
			}
			do {

				result = CM[curOrder].GetInterval(context, curSymbol, curInterval, &mask[0]);
				if (result != 2) { // если контекст существует
					RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq);
				}
				--curOrder;
			} while ( result != 0  && curOrder>=0); //пока окончательно не закодировали символ и не зашли за границу порядка

			if (result != 0) { //кодируем по равновероятностной модели
				for (i = 0, cumFreq = 0; i < 256; ++i) {
					if (mask[i] == 0) {
						if (i == (int)curSymbol) {
							curInterval.cumFreq = cumFreq;
							curInterval.curFreq = 1;
						}
						cumFreq += 1;
					}
				}
				curInterval.totalFreq = cumFreq + 1;
				RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq);
			}

			for (curOrder=0; curOrder <= ORDER; ++curOrder) {
				CM[curOrder].UpdateContextModel(context, curSymbol);
			}

			context.push_back(curSymbol);
			context = cutString(context,ORDER);
		}
	} while ( !inputFile.FEOF() );



	 //записываем символ конца файла. Он кодируется как уход в модели -1 порядка
	curOrder = ORDER;
	for (i = 0; i < 256; ++i) {
		mask[i] = 0;
	}

	do {
		result = CM[curOrder].GetInterval(context, curSymbol, curInterval,&mask[0], true);

		if (result != 2) { // если контекст существует
			RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq);
		}
		--curOrder;
	} while ( curOrder>=0); //пока окончательно не закодировали символ и не зашли за границу порядка
	//кодируем по равновероятностной модели
	for (i = 0, cumFreq = 0; i < 256; ++i) {
		if (mask[i] == 0) {
			cumFreq += 1;
		}
	}
	curInterval.cumFreq = cumFreq;
	curInterval.curFreq = 1;
	curInterval.totalFreq = cumFreq + 1;
	RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq);


	RC.FinishEncode();

	fseek(f,0,SEEK_SET);

	while (!feof(f)) {
		 result = fread(&curSymbol, sizeof(curSymbol),1,f);
		 outputFile.Write(&curSymbol,sizeof(curSymbol));
	}
	fclose(f);


	delete[] CM;
	return 0;
}
Пример #7
0
int PPMCompressor::DecompressFile(BitFile &inputFile, BitFile &outputFile,bool paramVerbose) {

	int result;
	unsigned int i;
	long int fSize;
	int curOrder, curDecodeOrder;
	unsigned int cum_freq=0, totFreq, CumFreqUnder;
	unsigned int mask[256];
	bool EndOfFile, found;
	std::string context;
	RangeCoder RC;
	ContextModel *CM;
	Intervals curInterval;
	unsigned char curSymbol;
	FILE *f;


	f = tmpfile();

	while (inputFile.FEOF() == false) {
			 result = inputFile.Read(&curSymbol, sizeof(curSymbol));
			 result = fwrite(&curSymbol, sizeof(curSymbol),1, f);
	}

	fseek(f,0,SEEK_SET);

	//инициализация
	RC.StartDecode(f);

	CM = new ContextModel[ORDER+1];
	for (curOrder = 0; curOrder <= ORDER; ++curOrder) {
		CM[curOrder].SetOrder(curOrder);
	}

	context = "";
	curDecodeOrder = -1;
	totFreq = 257;
	EndOfFile = false;

	for (i = 0; i < 256; ++i) {
		mask[i] = 0;
	}

	fSize = inputFile.GetFileSize();
	if (paramVerbose)  printProcentsBar(0,fSize);


	 do {

		cum_freq = RC.get_freq(totFreq);

		if (curDecodeOrder == -1) {

			for (i = 0, found = false, CumFreqUnder = 0; i < 256; ++i) {

				if (mask[i] == 0) {
					if  ( found == false && (CumFreqUnder + 1) > cum_freq ) {
						curSymbol = (unsigned char)i;
						curInterval.cumFreq = CumFreqUnder;
						curInterval.curFreq = 1;
						found = true;
					}
				CumFreqUnder += 1;
				mask[i] = 1;
				}
			}

			curInterval.totalFreq = CumFreqUnder + 1;

			if (found == false) {
				EndOfFile = true;
				curInterval.curFreq = 1;
				curInterval.cumFreq = CumFreqUnder;
			}



			RC.decode_update(curInterval.cumFreq,curInterval.curFreq, curInterval.totalFreq);

			if (found == true) {
				outputFile.Write(&curSymbol, sizeof(curSymbol));

				for (curOrder=0; curOrder <= ORDER; ++curOrder) {
					CM[curOrder].UpdateContextModel(context, curSymbol);
				}

				if (paramVerbose) printProcentsBar(ftell(f),fSize);


				context.push_back(curSymbol);
				context = cutString(context,ORDER);

				for (i = 0; i < 256; ++i) {
					mask[i] = 0;
				}

				//находим значение максимального порядка, по которому будем декодировать
				curDecodeOrder = ORDER;
				for (curOrder = curDecodeOrder, totFreq = 0; curOrder >= 0 && totFreq == 0; --curOrder) {
					totFreq = CM[curOrder].GetTotalFreq( cutString(context, curOrder));
					curDecodeOrder = curOrder;
				}
				if (totFreq == 0) {
					totFreq = 257;
					curDecodeOrder = -1;
				}
			}

		}
		else {
			result = CM[curDecodeOrder].GetSymbol( cutString(context, curDecodeOrder) , cum_freq,curSymbol,curInterval, &mask[0]);

			RC.decode_update(curInterval.cumFreq,curInterval.curFreq, curInterval.totalFreq);

			if (result == 0) {
				outputFile.Write(&curSymbol, sizeof(curSymbol));

				for (curOrder=0; curOrder <= ORDER; ++curOrder) {
					CM[curOrder].UpdateContextModel(context, curSymbol);
				}

				if (paramVerbose)  printProcentsBar(ftell(f),fSize);

				context.push_back(curSymbol);
				context = cutString(context,ORDER);

				for (i = 0; i < 256; ++i) {
					mask[i] = 0;
				}

				//находим значение максимального порядка, по которому можно декодировать
				curDecodeOrder = ORDER;
				for (curOrder = curDecodeOrder, totFreq = 0; curOrder >= 0 && totFreq == 0; --curOrder) {
					totFreq = CM[curOrder].GetTotalFreq( cutString(context, curOrder));
					curDecodeOrder = curOrder;
				}
				if (totFreq == 0) {
					totFreq = 257;
					curDecodeOrder = -1;
				}

			}
			else {
				--curDecodeOrder;

				if (curDecodeOrder>=0) {
					totFreq = CM[curDecodeOrder].GetTotalFreq( cutString(context, curDecodeOrder) , &mask[0]);
				} else {
					for (i = 0, CumFreqUnder = 0; i<256; ++i) {
						if (mask[i] == 0) {
							CumFreqUnder += 1;
						}
					}
					totFreq = CumFreqUnder + 1;
				}


			}

		}
	}while (!feof(f) && !EndOfFile);


	 if (paramVerbose)  printProcentsBar(fSize,fSize);

	RC.FinishDecode();
	fclose(f);

	delete[] CM;
	return 0;
}
Пример #8
0
void liqRibData::addAdditionalSurfaceParameters( MObject node )
{
  LIQDEBUGPRINTF("-> scanning for additional rman surface attributes \n");
  MStatus status( MS::kSuccess );

  // work out how many elements there would be in a facevarying array if a mesh or subD
  // faceVaryingCount is a private data member
  if ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) 
  {
    faceVaryingCount = 0;
    MFnMesh fnMesh( node );
    for ( unsigned pOn( 0 ); pOn < fnMesh.numPolygons(); pOn++ ) 
      faceVaryingCount += fnMesh.polygonVertexCount( pOn );
  }
  // find how many additional
  MFnDependencyNode nodeFn( node );

  // find the attributes
  MStringArray floatAttributesFound  = findAttributesByPrefix( "rmanF", nodeFn );
  MStringArray pointAttributesFound  = findAttributesByPrefix( "rmanP", nodeFn );
  MStringArray vectorAttributesFound = findAttributesByPrefix( "rmanV", nodeFn );
  MStringArray normalAttributesFound = findAttributesByPrefix( "rmanN", nodeFn );
  MStringArray colorAttributesFound  = findAttributesByPrefix( "rmanC", nodeFn );
  MStringArray stringAttributesFound = findAttributesByPrefix( "rmanS", nodeFn );

  if ( floatAttributesFound.length() > 0 ) 
  {
    for ( unsigned i( 0 ); i < floatAttributesFound.length(); i++ ) 
    {
      liqTokenPointer tokenPointerPair;
      MString cutString( floatAttributesFound[i].substring( 5, floatAttributesFound[i].length() ) );
      MPlug fPlug( nodeFn.findPlug( floatAttributesFound[i] ) );
      MObject plugObj;
      status = fPlug.getValue( plugObj );
      if ( plugObj.apiType() == MFn::kDoubleArrayData ) 
      {
        MFnDoubleArrayData fnDoubleArrayData( plugObj );
        const MDoubleArray& doubleArrayData( fnDoubleArrayData.array( &status ) );
        tokenPointerPair.set( cutString.asChar(),
                              rFloat,
                              true,
                              false,
                              doubleArrayData.length() );
        for ( unsigned kk( 0 ); kk < doubleArrayData.length(); kk++ ) 
					tokenPointerPair.setTokenFloat( kk, doubleArrayData[kk] );
        
        if ( ( type() == MRT_NuCurve ) && ( cutString == MString( "width" ) ) ) 
          tokenPointerPair.setDetailType( rVarying );
        else if ( ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) && 
									( doubleArrayData.length() == faceVaryingCount ) ) 
          tokenPointerPair.setDetailType( rFaceVarying);
        else 
          tokenPointerPair.setDetailType( rVertex );
      } 
      else 
      {
        if ( fPlug.isArray() ) 
        {
          unsigned nbElts( fPlug.evaluateNumElements() );
          float floatValue;
          tokenPointerPair.set( cutString.asChar(),
                                rFloat,
                                false,
                                true, // philippe :passed as uArray, otherwise it will think it is a single float
                                nbElts );
          MPlug elementPlug;
          for ( unsigned kk( 0 ); kk < nbElts; kk++ ) 
          {
            elementPlug = fPlug.elementByPhysicalIndex(kk);
            elementPlug.getValue( floatValue );
            tokenPointerPair.setTokenFloat( kk, floatValue );
          }
          tokenPointerPair.setDetailType( rConstant );
        } 
        else 
        {
          float floatValue;
          tokenPointerPair.set( cutString.asChar(), rFloat );
          fPlug.getValue( floatValue );
          tokenPointerPair.setTokenFloat( 0, floatValue );
          tokenPointerPair.setDetailType( rConstant );
        }
      }
      tokenPointerArray.push_back( tokenPointerPair );
    }
  }
  if ( pointAttributesFound.length() > 0 ) 
  {
    for ( unsigned i( 0 ); i < pointAttributesFound.length(); i++ ) 
    {
      liqTokenPointer tokenPointerPair;
      MString cutString( pointAttributesFound[i].substring( 5, pointAttributesFound[i].length() ) );
      MPlug pPlug( nodeFn.findPlug( pointAttributesFound[i] ) );
      MObject plugObj;
      status = pPlug.getValue( plugObj );
      if ( plugObj.apiType() == MFn::kPointArrayData ) 
      {
        MFnPointArrayData  fnPointArrayData( plugObj );
        MPointArray pointArrayData = fnPointArrayData.array( &status );
        tokenPointerPair.set( cutString.asChar(),
                              rPoint,
                              //( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false,
                              true,
                              false,
                              pointArrayData.length() );
        if ( type() == MRT_Nurbs || type() == MRT_NuCurve ) 
          for ( unsigned kk( 0 ); kk < pointArrayData.length(); kk++ ) 
            tokenPointerPair.setTokenFloat( kk, pointArrayData[kk].x, pointArrayData[kk].y, pointArrayData[kk].z, pointArrayData[kk].w );
        else 
          for ( unsigned kk( 0 ); kk < pointArrayData.length(); kk++ ) 
            tokenPointerPair.setTokenFloat( kk, pointArrayData[kk].x, pointArrayData[kk].y, pointArrayData[kk].z );
        tokenPointerPair.setDetailType( rVertex );
      } 
      else 
      {
        // Hmmmm float ? double ?
        float x, y, z;
        tokenPointerPair.set( cutString.asChar(), rPoint );
        // Hmmm should check as for arrays if we are in nurbs mode : 4 values
        pPlug.child(0).getValue( x );
        pPlug.child(1).getValue( y );
        pPlug.child(2).getValue( z );
        tokenPointerPair.setTokenFloat( 0, x, y, z );
        tokenPointerPair.setDetailType( rConstant );
      }
      tokenPointerArray.push_back( tokenPointerPair );
    }
  }
  parseVectorAttributes( nodeFn, vectorAttributesFound, rVector );
  parseVectorAttributes( nodeFn, normalAttributesFound, rNormal );
  parseVectorAttributes( nodeFn, colorAttributesFound,  rColor  );

  if ( stringAttributesFound.length() > 0 ) 
  {
    for ( unsigned i( 0 ); i < stringAttributesFound.length(); i++ ) 
    {
      liqTokenPointer tokenPointerPair;
      MString cutString( stringAttributesFound[i].substring( 5, stringAttributesFound[i].length() ) );
      MPlug sPlug( nodeFn.findPlug( stringAttributesFound[i] ) );
      MObject plugObj;
      status = sPlug.getValue( plugObj );
      tokenPointerPair.set( cutString.asChar(), rString );
      MString stringVal;
      sPlug.getValue( stringVal );
      tokenPointerPair.setTokenString( 0, stringVal.asChar() );
      tokenPointerPair.setDetailType( rConstant );
      tokenPointerArray.push_back( tokenPointerPair );
    }
  }
}
Пример #9
0
void TodoDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
  KColorScheme colorScheme( option.palette.currentColorGroup() );
  QPen pen;
  
//  if( option.state & QStyle::State_Selected ){
//    painter->fillRect(option.rect, option.palette.highlight() );
//  }
  
  QPoint originPoint = option.rect.topLeft();
  originPoint.rx()++;
  originPoint.ry()++;
  
  QMap<QString,QVariant> map( index.data().toMap() );
  
  QStyleOptionViewItem newOption = option;
  if( map["type"] == 1 ){
    switch( map["priority"].toInt() ){
    case 1:
      if( Settings::self()->getUseOwnColor() ){
        newOption.palette.setColor(QPalette::Background, Settings::self()->getPriority1() );
      } else {
        newOption.palette.setColor(QPalette::Background, colorScheme.background(KColorScheme::NegativeBackground).color());
      }
      if( Settings::self()->getUseOwnFontColor() ){
        pen.setColor( Settings::self()->getPriority1Font() );
      }
      painter->fillRect(newOption.rect, newOption.palette.background());
      break;
    case 2:
      if( Settings::self()->getUseOwnColor() ){
        newOption.palette.setColor(QPalette::Background, Settings::self()->getPriority2() );
      } else {
        newOption.palette.setColor(QPalette::Background, colorScheme.background(KColorScheme::NeutralBackground).color());
      }
      if( Settings::self()->getUseOwnFontColor() ){
        pen.setColor( Settings::self()->getPriority2Font() );
      }
      painter->fillRect(newOption.rect, newOption.palette.background());
      break;
    case 3:
      if( Settings::self()->getUseOwnColor() ){
        newOption.palette.setColor(QPalette::Background, Settings::self()->getPriority3() );
      } else {
        newOption.palette.setColor(QPalette::Background, colorScheme.background(KColorScheme::PositiveBackground).color());
      }
      if( Settings::self()->getUseOwnFontColor() ){
        pen.setColor( Settings::self()->getPriority3Font() );
      }
      painter->fillRect(newOption.rect, newOption.palette.background());
      break;
    default:
      newOption.palette.setColor(QPalette::Background, colorScheme.background(KColorScheme::NormalBackground).color());
      break;
    }
    painter->fillRect(newOption.rect, newOption.palette.background());
    //qDebug() << newOption.palette.background().color().toRgb();
  }  
  painter->save();
  QStyledItemDelegate::paint(painter,newOption,index);
  painter->restore();
  
  if( map["type"] == 0 ){
    if( index.column() != 0 ){
      return;
    }
    QString iconName;
    if( view->isExpanded(index) ){
      iconName = "arrow-down";
    } else {
      iconName = "arrow-right";
    }
    QRect iconRect(originPoint, QSize(15,15));
    painter->drawPixmap(iconRect, KIcon(iconName).pixmap(QSize(15,15)) );
    painter->save();
    painter->setFont(boldFont);
    QPoint writePoint( originPoint + QPoint(iconRect.size().width()+5,0) );
    QString text = cutString( map["name"].toString(), QRect( writePoint, newOption.rect.bottomRight() ), boldFont );
    painter->drawText( QRect( writePoint, newOption.rect.bottomRight() ), text );
    painter->restore();
  }
  
  if( map["type"] == 1 ){
    painter->save();
    painter->setPen(pen);
    originPoint.ry()++;
    if( index.column() == 0 ){
      originPoint.rx() += 25; // for the checkbox
      QString text = map["name"].toString();
//      if( map["priority"].toInt() == 4 ){
//        text.prepend("- ");
//      } else {
//        text.prepend( QString::number(map["priority"].toInt()) + " " );
//      }
      text = cutString( text, QRect(originPoint,newOption.rect.bottomRight()), standardFont );
      painter->drawText( QRect(originPoint,newOption.rect.bottomRight()), text );
    } else {
      QString text = cutString( map["date"].toDate().toString(), QRect(originPoint,newOption.rect.bottomRight()), standardFont );
      painter->drawText( QRect(originPoint,newOption.rect.bottomRight()), text);
      if(map["date"].toDate().isNull()){
        painter->drawText( QRect(originPoint,newOption.rect.bottomRight()), "-");
      }
    }
    painter->restore();
  }
}
Пример #10
0
void Evaluation::print (FILE *file, PRINT::List format) {

	if (!_conf_mat_ptr) {
		ssi_wrn ("nothing to print");
		return;
	}
		
	ssi_size_t max_label_len = 0;
	for (ssi_size_t i = 0; i < _n_classes; ++i) {
		ssi_size_t len = ssi_cast (ssi_size_t, strlen (_class_names[i]));
		if (len > max_label_len) {
			max_label_len = len;
		}
	}

	if (format == PRINT::CSV || format == PRINT::CSV_EX) {

		File *tmp = File::Create(File::ASCII, File::WRITE, 0, file);
		tmp->setType(SSI_UINT);
		tmp->setFormat(";", "");

		ssi_fprint(file, "#classes;%u\n", _n_classes);
		ssi_fprint(file, "#total;%u\n", _n_classified + _n_unclassified);
		ssi_fprint(file, "#classified;%u\n", _n_classified);
		ssi_fprint(file, "#unclassified;%u\n", _n_unclassified);

		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, ";%s", _class_names[i]);
		}

		ssi_fprint(file, "\n");
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "%s;", _class_names[i]);
			tmp->write(_conf_mat_ptr[i], 0, _n_classes);
			ssi_fprint(file, "%f\n", 100 * get_class_prob(i));
		}
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "; ");
		}
		ssi_fprint(file, ";%f;%f\n", 100 * get_classwise_prob(), 100 * get_accuracy_prob());

		if (format == PRINT::CSV_EX) {
			ssi_fprint(file, "\ntruth;prediction\n");
			ssi_size_t *ptr = _result_vec;
			for (ssi_size_t i = 0; i < _n_total; i++) {
				ssi_fprint(file, "%u;%u\n", ptr[0], ptr[1]);
				ptr += 2;
			}
		}

	} else {

		File *tmp = File::Create(File::ASCII, File::WRITE, 0, file);
		tmp->setType(SSI_UINT);
		tmp->setFormat(" ", "6");

		ssi_fprint(file, "#classes:      %u\n", _n_classes);
		ssi_fprint(file, "#total:        %u\n", _n_classified + _n_unclassified);
		ssi_fprint(file, "#classified:   %u\n", _n_classified);
		ssi_fprint(file, "#unclassified: %u\n", _n_unclassified);

		if (format != PRINT::CONSOLE_EX) {
			for (ssi_size_t j = 0; j < max_label_len + 3; j++) {
				ssi_fprint(file, " ");
			}
			ssi_char_t cut[7];
			for (ssi_size_t i = 0; i < _n_classes; ++i) {
				cutString(_class_names[i], 7, cut);
				ssi_fprint(file, " %6s", cut);
			}
		}
		ssi_fprint(file, "\n");
		for (ssi_size_t i = 0; i < _n_classes; ++i) {
			ssi_fprint(file, "%*s: ", max_label_len, _class_names[i]);
			tmp->write(_conf_mat_ptr[i], 0, _n_classes);
			ssi_fprint(file, "   -> %8.2f%%\n", 100 * get_class_prob(i));
		}
		ssi_fprint(file, "   %*s  => %8.2f%% | %.2f%%\n", max_label_len + _n_classes * 7, "", 100 * get_classwise_prob(), 100 * get_accuracy_prob());
		delete tmp;
	}

	fflush (file);
}