示例#1
0
string ClsFEGroupPlot::wSpacePlotSelected2Range(QArray<int> &qarraySelected){
    string strRange;

 
    if(dynamic_cast<ClsTopologySparse*>(ClsFESystemManager::Instance()->getFEGroup( strGroupID )->getTopology())){
	ClsTopologySparse *clsTopologySparse = dynamic_cast<ClsTopologySparse*>(ClsFESystemManager::Instance()->getFEGroup( strGroupID )->getTopology());
	iGroupWidth = clsTopologySparse->nrCellsHorizontal();
	iGroupHeight = clsTopologySparse->nrCellsVertical();

	for(unsigned int ii = 0; ii< qarraySelected.size(); ii++){
	    int iy = int(qarraySelected[ii] / iGroupWidth) + 1;
	    int ix = qarraySelected[ii] - int(qarraySelected[ii] / iGroupWidth) * iGroupWidth + 1;
	    if(clsTopologySparse->isValidCell(ix, iy)){
//		cout << "clsTopologySparse->pos2index(ix, iy): " << clsTopologySparse->pos2index(ix, iy) << endl;
//		cout << __FILE__ << ": ix, iy: " << ix << ", " << iy << endl;
		strRange = iqrUtils::int2string(clsTopologySparse->pos2index(ix, iy)) + ";"  +  strRange ;
	    }
	}	      
    } else {
	for(unsigned int ii = 0; ii< qarraySelected.size(); ii++){
	    strRange = iqrUtils::int2string(qarraySelected[ii]) + ";"  +  strRange ;
	}
    }
    return strRange;
}
示例#2
0
/*!
    Replaces the elements of this index buffer, starting at \a index,
    with the contents of \a values.  All other elements keep their
    current values.

    If the index buffer has been uploaded to the GL server, then this
    function must be called with a current GL context that is compatible
    with the uploaded buffer.

    The index buffer must have been originally created with the
    int element type.

    OpenGL/ES systems usually do not support 32-bit index values unless
    they have a special extension for that purpose.  On systems without
    32-bit index values, this function will need to convert all values
    to 16-bit which may incur a performance penalty and lose information.

    \sa setIndexes()
*/
void QGLIndexBuffer::replaceIndexes(int index, const QArray<uint>& values)
{
    Q_D(QGLIndexBuffer);
    Q_ASSERT_X(d->elementType == GL_UNSIGNED_INT || !d->hasIntBuffers,
               "QGLIndexBuffer::replaceIndexes()",
               "buffer created with ushort element type, replacing with int");
    if (d->elementType != GL_UNSIGNED_INT && d->hasIntBuffers)
        return;
    if (d->buffer.isCreated()) {
        if (d->hasIntBuffers) {
            d->buffer.bind();
            d->buffer.write(index * sizeof(int),
                            values.constData(), values.size() * sizeof(int));
            d->buffer.release();
        } else {
            QArray<ushort> svalues = qt_qarray_uint_to_ushort(values);
            d->buffer.bind();
            d->buffer.write(index * sizeof(ushort),
                            svalues.constData(),
                            svalues.size() * sizeof(ushort));
            d->buffer.release();
        }
    } else if (d->elementType == GL_UNSIGNED_INT) {
        d->indexesInt.replace(index, values.constData(), values.size());
        d->indexCount = d->indexesInt.size();
    } else {
        QArray<ushort> svalues = qt_qarray_uint_to_ushort(values);
        d->indexesShort.replace(index, svalues.constData(), svalues.size());
        d->indexCount = d->indexesShort.size();
    }
}
示例#3
0
bool AbView::contactCompare( const Opie::OPimContact &cnt, int category )
{
    //    odebug << "bool AbView::contactCompare( const Opie::OPimContact &cnt, "
    //                    << category << " )" << oendl;

    bool returnMe;
    QArray<int> cats;
    cats = cnt.categories();

    //    odebug << "Number of categories: " << cats.count() << oendl;

    returnMe = false;
    if ( cats.count() == 0 && category == -1 )
        // Contacts with no category will just shown on "All" and "Unfiled"
        returnMe = true;
    else {
        int i;
        for ( i = 0; i < int(cats.count()); i++ ) {
            //odebug << "Comparing " << cats[i] << " with " << category << oendl;
            if ( cats[i] == category ) {
                returnMe = true;
                break;
            }
        }
    }
    //    odebug << "Return: " << returnMe << oendl;
    return returnMe;
}
示例#4
0
/*!
    Returns a copy of this array of QVector2D values, translated
    by the components of \a value.

    \sa translate()
*/
QArray<QVector2D> QVector2DArray::translated(const QVector2D& value) const
{
    QArray<QVector2D> result;
    int size = count();
    QVector2D *dst = result.extend(size);
    const QVector2D *src = constData();
    for (int index = 0; index < size; ++index)
        *dst++ = *src++ + value;
    return result;
}
示例#5
0
/*!
    Returns a copy of this array of QVector3D values, multiplied
    by the \a scale.

    \sa scale()
*/
QVector3DArray QVector3DArray::scaled(qreal scale) const
{
    QArray<QVector3D> result;
    int size = count();
    const QVector3D *src = constData();
    QVector3D *dst = result.extend(size);
    for (int index = 0; index < size; ++index)
        *dst++ = *src++ * scale;
    return result;
}
示例#6
0
int main()
{
    std::cout << "version=" << QT_VERSION_STR << std::endl;

    QArray<int> a = fib( 6 );               // get 6 first fibonaccis

    if(4==a.find(5))
	return 0;
    return 1;
}
示例#7
0
/*!
    Returns a copy of this array of QVector2D values,
    transformed by \a matrix.

    \sa transform()
*/
QArray<QVector2D> QVector2DArray::transformed(const QMatrix4x4& matrix) const
{
    QArray<QVector2D> result;
    int size = count();
    const QVector2D *src = constData();
    QVector2D *dst = result.extend(size);
    for (int index = 0; index < size; ++index)
        *dst++ = (matrix * QVector3D(*src++, 0.0f)).toVector2D();
    return result;
}
示例#8
0
/*! Returns a list of all labels associated with the \a catids */
QStringList CategoryGroup::labels(const QArray<int> &catids ) const
{
    QStringList labels;
    if ( catids.count() == 0 )
	return labels;
    for ( QMap<int, QString>::ConstIterator it = mIdLabelMap.begin();
	  it != mIdLabelMap.end(); ++it )
	if ( catids.find( it.key() ) != -1 )
	    labels += *it;
    return labels;
}
OEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
{
	QArray<int> rawRepUids = rawRepeats();
	OEvent::ValueList list;

	for (uint i = 0; i < rawRepUids.count(); ++i ){
		list.append( find( rawRepUids[i] ) );
	}

	return list;
}
示例#10
0
/*!
    Returns a copy of this array of QVector2D values, multiplied
    by the \a scale.

    \sa scale()
*/
QVector2DArray QVector2DArray::scaled(qreal scale) const
{
    const qreal identity = 1.0;
    if (qFuzzyCompare(scale, identity))
        return *this;
    QArray<QVector2D> result;
    int size = count();
    const QVector2D *src = constData();
    QVector2D *dst = result.extend(size);
    for (int index = 0; index < size; ++index)
        *dst++ = *src++ * scale;
    return result;
}
示例#11
0
// Exporting Event data to map. Using the same
// encoding as ODateBookAccessBackend_xml does..
// Thus, we could remove the stuff there and use this
// for it and for all other places..
// Encoding should happen at one place, only ! (eilers)
QMap<int, QString> OEvent::toMap()const {
    QMap<int, QString> retMap;

    retMap.insert( OEvent::FUid, QString::number( uid() ) );
    retMap.insert( OEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ));
    retMap.insert( OEvent::FDescription, Qtopia::escapeString( description() ) );
    retMap.insert( OEvent::FLocation, Qtopia::escapeString( location() ) );
    retMap.insert( OEvent::FType, isAllDay() ? "AllDay" : "" );
    OPimAlarm alarm = notifiers().alarms()[0];
    retMap.insert( OEvent::FAlarm, QString::number( alarm.dateTime().secsTo(  startDateTime() ) / 60 ) );
    retMap.insert( OEvent::FSound, (alarm.sound() == OPimAlarm::Loud) ? "loud" : "silent" );

    OTimeZone zone(  timeZone().isEmpty() ? OTimeZone::current() : timeZone() );
    retMap.insert( OEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime(  startDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime(  endDateTime(), OTimeZone::utc() ) ) ) );
    retMap.insert( OEvent::FNote, Qtopia::escapeString( note() ) );
    retMap.insert( OEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
    if( parent() )
	    retMap.insert( OEvent::FRecParent, QString::number( parent() ) );
    if( children().count() ){
            QArray<int> childr = children();
	    QString buf;
            for ( uint i = 0; i < childr.count(); i++ ) {
		    if ( i != 0 ) buf += " ";
		    buf += QString::number( childr[i] );
            }
	    retMap.insert( OEvent::FRecChildren, buf );
    }

    // Add recurrence stuff
    if( hasRecurrence() ){
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
	    retMap.insert( OEvent::FRWeekdays, recFields[ORecur::RWeekdays] );
	    retMap.insert( OEvent::FRPosition, recFields[ORecur::RPosition] );
	    retMap.insert( OEvent::FRFreq, recFields[ORecur::RFreq] );
	    retMap.insert( OEvent::FRHasEndDate, recFields[ORecur::RHasEndDate] );
	    retMap.insert( OEvent::FREndDate, recFields[ORecur::EndDate] );
	    retMap.insert( OEvent::FRCreated, recFields[ORecur::Created] );
	    retMap.insert( OEvent::FRExceptions, recFields[ORecur::Exceptions] );
    } else {
	    ORecur recur = recurrence();
	    QMap<int, QString> recFields = recur.toMap();
	    retMap.insert( OEvent::FRType, recFields[ORecur::RType] );
    }

    return retMap;
}
示例#12
0
static void find_trans_colors()
{
    struct OverlayProp {
	long  visual;
	long  type;
	long  value;
	long  layer;
    };

    trans_colors_init = TRUE;

    Display* appDisplay = QPaintDevice::x11AppDisplay();
    QWidget* rootWin = QApplication::desktop();
    if ( !rootWin )
	return;					// Should not happen
    Atom overlayVisualsAtom = XInternAtom( appDisplay,
					   "SERVER_OVERLAY_VISUALS", True );
    if ( overlayVisualsAtom == None )
	return;					// Server has no overlays

    Atom actualType;
    int actualFormat;
    ulong nItems;
    ulong bytesAfter;
    OverlayProp* overlayProps = 0;
    int res = XGetWindowProperty( appDisplay, rootWin->winId(),
				  overlayVisualsAtom, 0, 10000, False, 
				  overlayVisualsAtom, &actualType, 
				  &actualFormat, &nItems, &bytesAfter,
				  (uchar**)&overlayProps );

    if ( res != Success || actualType != overlayVisualsAtom
	 || actualFormat != 32 || nItems < 4 || !overlayProps )
	return;					// Error reading property
	
    int numProps = nItems / 4;
    trans_colors.resize( numProps );
    int j = 0;
    for ( int i = 0; i < numProps; i++ ) {
	if ( overlayProps[i].type == 1 ) {
	    trans_colors[j].vis = (VisualID)overlayProps[i].visual;
	    trans_colors[j].color = (int)overlayProps[i].value;
	    j++;
	}
    }
    XFree( overlayProps );
    trans_colors.truncate( j );
}
示例#13
0
/*!
    Sets the index \a values in this index buffer, replacing the
    entire current contents.

    If the index buffer has been uploaded to the GL server, then this
    function must be called with a current GL context that is compatible
    with the uploaded buffer.

    \sa replaceIndexes()
*/
void QGLIndexBuffer::setIndexes(const QArray<ushort>& values)
{
    Q_D(QGLIndexBuffer);
    if (d->buffer.isCreated()) {
        d->buffer.bind();
        d->buffer.allocate(values.constData(), values.size() * sizeof(ushort));
        d->buffer.release();
        // The element type may have changed from int to ushort.
        d->elementType = GL_UNSIGNED_SHORT;
    } else {
        d->indexesShort = values;
        d->elementType = GL_UNSIGNED_SHORT;
        d->indexesInt = QArray<uint>();
    }
    d->indexCount = values.size();
}
示例#14
0
/*!

  Returns all ids associated with the application CategoryGroup \a app
  and the passed in \a labels in that group.
*/
QArray<int> Categories::ids( const QString &app, const QStringList &labels) const
{
  QArray<int> results;
  QStringList::ConstIterator it;
  int i;

  for ( i=0, it=labels.begin(); it!=labels.end(); i++, ++it ) {
    int value = id( app, *it );
    if ( value != 0 ) {
      int tmp = results.size();
      results.resize( tmp + 1 );
      results[ tmp ] = value;
    }
  }
  return results;
}
/*!
  \internal
    Processes a list of floating point numbers.  If the list contains only 1
    element, a QVariant<float> is returned.  If the list containst 2, 3 or 4
    elements, they are converted into a QVariant containing a QVector2D,
    QVector3D, or QVector4D respectively.
    If the list containst more elements than that, they are returned as a
    QArray<float>.

*/
QVariant QGLColladaFxEffectFactory::processFloatList( QXmlStreamReader& xml )
{
    QArray<float> floats;
    QString elementString = xml.readElementText();
    QStringList list = elementString.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
    bool ok;
    float f;
    foreach( QString string, list )
    {
        f = string.toFloat( &ok );
        if( ok )
            floats.append(string.toFloat());
        else
        {
            qWarning() << "Warning: malformed float ( line" << xml.lineNumber() << ")";
        }
    }
示例#16
0
static QArray<ushort> qt_qarray_uint_to_ushort(const QArray<uint> &array)
{
    QArray<ushort> result;
    const uint *values = array.constData();
    int size = array.size();
    bool largeValue = false;
    result.reserve(size);
    while (size-- > 0) {
        uint value = *values++;
        if (ushort(value) != value)
            largeValue = true;
        result.append(ushort(value));
    }
    if (largeValue)
        qWarning("QGLIndexBuffer::setIndexes: large 32-bit value provided to a 16-bit only buffer");
    return result;
}
示例#17
0
/** Get a vector of Rfcomm channels of the services having "uuid" in the class ID List*/
QArray<int> OTPeer::rfcommList( const OTUUID & uuid) {

    QArray<int> rfcommList;
    unsigned int channel;

    for( unsigned int i = 0;
         i < serviceList.count();
         i ++ ) {
      if( serviceList[i]->hasClassID(uuid)) {
        if( serviceList[i]->rfcommChannel(channel) ) {
          rfcommList.resize( rfcommList.size()+1 );
          rfcommList[rfcommList.size()-1] = channel;
        }
      }
    }
    return rfcommList;
}
示例#18
0
文件: wSpacePlot.cpp 项目: jeez/iqr
void WSpacePlot::setSelecIndexList(QArray<int> &list) {

  clearSelection();
  for (unsigned int i=0; i<list.count(); i++) 
    cellData[list[i]].attr|=selected;
   
  selecIndexList=list;
}
示例#19
0
ViewportPrivate::ViewportPrivate()
    : picking(true)
    , showPicking(false)
    , navigation(true)
    , blending(false)
    , itemsInitialized(false)
    , needsPick(true)
    , camera(0)
    , lightModel(0)
    , backdrop(0)
    , backgroundColor(Qt::black)
    , view(0)
    , viewWidget(0)
    , pickId(1)
    , pickFbo(0)
{
    // Construct the vertices for a quad with (0, 0) as the
    // texture co-ordinate for the bottom-left of the screen
    // and (1, 1) as the texture co-ordinate for the top-right.
    backdropVertices.setPackingHint(QGLVertexBuffer::Append);

    QArray<QVector2D> pos;
    pos.append(QVector2D(-1.0f, -1.0f));
    pos.append(QVector2D(-1.0f,  1.0f));
    pos.append(QVector2D( 1.0f,  1.0f));
    pos.append(QVector2D( 1.0f, -1.0f));

    QArray<QVector2D> tex;
    pos.append(QVector2D(0.0f, 0.0f));
    pos.append(QVector2D(0.0f, 1.0f));
    pos.append(QVector2D(1.0f, 1.0f));
    pos.append(QVector2D(1.0f, 0.0f));

    backdropVertices.addAttribute(QGL::Position, pos);
    backdropVertices.addAttribute(QGL::TextureCoord0, tex);

    //backdropVertices.append(-1.0f, -1.0f);
    //backdropVertices.append(0.0f, 0.0f);
    //backdropVertices.append(-1.0f, 1.0f);
    //backdropVertices.append(0.0f, 1.0f);
    //backdropVertices.append(1.0f, 1.0f);
    //backdropVertices.append(1.0f, 1.0f);
    //backdropVertices.append(1.0f, -1.0f);
    //backdropVertices.append(1.0f, 0.0f);
}
示例#20
0
/*!
    Replaces the elements of this index buffer, starting at \a index,
    with the contents of \a values.  All other elements keep their
    current values.

    If the index buffer has been uploaded to the GL server, then this
    function must be called with a current GL context that is compatible
    with the uploaded buffer.

    The index buffer must have been originally created with the
    ushort element type.

    \sa setIndexes()
*/
void QGLIndexBuffer::replaceIndexes(int index, const QArray<ushort>& values)
{
    Q_D(QGLIndexBuffer);
    Q_ASSERT_X(d->elementType == GL_UNSIGNED_SHORT,
               "QGLIndexBuffer::replaceIndexes()",
               "buffer created with int element type, replacing with ushort");
    if (d->elementType != GL_UNSIGNED_SHORT)
        return;
    if (d->buffer.isCreated()) {
        d->buffer.bind();
        d->buffer.write(index * sizeof(ushort),
                        values.constData(), values.size() * sizeof(ushort));
        d->buffer.release();
    } else {
        d->indexesShort.replace(index, values.constData(), values.size());
        d->indexCount = d->indexesShort.size();
    }
}
示例#21
0
    void updateCatListFromArray()
    {
  Categories cat( 0 );
  cat.load( categoryFileName() );
  // we need to update the names for the mCat... to mCatList
        mCatList.clear();
        for (uint i = 0; i < mCat.count(); i++ )
            mCatList << cat.label("Document View", mCat[i] );

    }
示例#22
0
/*!
    Translates the elements in this array of QVector2D values
    by the components of \a value.

    \sa translated()
*/
void QVector2DArray::translate(const QVector2D& value)
{
    if (isDetached()) {
        // Modify the array in-place.
        int size = count();
        QVector2D *dst = data();
        for (int index = 0; index < size; ++index)
            *dst++ += value;
    } else {
        // Create a new array, translate the values, and assign.
        QArray<QVector2D> result;
        int size = count();
        const QVector2D *src = constData();
        QVector2D *dst = result.extend(size);
        for (int index = 0; index < size; ++index)
            *dst++ = *src++ + value;
        *this = result;
    }
}
示例#23
0
/*!
    Adds the color array \a value to this vertex bundle as the
    data for \a attribute.

    \sa upload()
*/
void QGLVertexBundle::addAttribute
    (QGL::VertexAttribute attribute, const QArray<QColor4ub>& value)
{
    Q_D(QGLVertexBundle);
    if (!d->buffer.isCreated()) {
        d->attributeSet.insert(attribute);
        d->attributes +=
            new QGLVertexBundleColorAttribute(attribute, value);
        d->vertexCount = qMax(d->vertexCount, value.count());
    }
}
示例#24
0
/*!
    Transforms the elements in this array of QVector2D values
    by \a matrix.

    \sa transformed()
*/
void QVector2DArray::transform(const QMatrix4x4& matrix)
{
    if (isDetached()) {
        // Modify the array in-place.
        int size = count();
        QVector2D *dst = data();
        for (int index = 0; index < size; ++index) {
            *dst = (matrix * QVector3D(*dst, 0.0f)).toVector2D();
            ++dst;
        }
    } else {
        // Create a new array, transform the values, and assign.
        QArray<QVector2D> result;
        int size = count();
        const QVector2D *src = constData();
        QVector2D *dst = result.extend(size);
        for (int index = 0; index < size; ++index)
            *dst++ = (matrix * QVector3D(*src++, 0.0f)).toVector2D();
        *this = result;
    }
}
示例#25
0
UIDArray ODateBookAccessBackend::sorted( const UIDArray& ar, bool asc, int sortOrder, int filter, const QArray<int>& categories )const {
    odebug << "Using Unaccelerated ODateBookAccessBackend sorted Implementation" << oendl;

    Internal::OPimEventSortVector vector( ar.count(), asc, sortOrder );
    int item = 0;

    for ( uint i = 0; i < ar.count(); ++i ){
	    OPimEvent event = find( ar[i], ar, i, Frontend::Forward );
	    if ( event.isEmpty() )
		    continue;

	    bool catPassed = true;
	    if ( filter & ODateBookAccess::FilterCategory ){
		    catPassed = false;
		    // Filter Categories
		    for ( uint cat_idx = 0; cat_idx < categories.count(); ++cat_idx ){
			    int cat = categories[cat_idx];
			    if ( cat == -1 || cat == 0 ){
				    // Unfiled. Check next category if list is not empty.
				    // Else: take it as we will not filter unfiled events..
				    if ( !event.categories().isEmpty() )
					    continue;
				    else
					    catPassed = true;
			    } else {
				    if ( !event.categories().contains( cat ) )
					    continue;
				    else{
					    catPassed = true;
					    break;
				    }
			    }
		    }
	    }

	    // Continue to next event if the category filter removed this item
	    if ( !catPassed )
		    continue;

	    vector.insert( item++, event );
    }

    // Now sort the vector and return the list of UID's
    vector.resize( item );
    vector.sort();

    UIDArray array( vector.count() );
    for ( uint i= 0; i < vector.count(); i++ )
        array[i] = vector.uidAt( i );

    return array;

}
示例#26
0
/*!
    Sets the index \a values in this index buffer, replacing the
    entire current contents.

    If the index buffer has been uploaded to the GL server, then this
    function must be called with a current GL context that is compatible
    with the uploaded buffer.

    OpenGL/ES systems usually do not support 32-bit index values unless
    they have a special extension for that purpose.  On systems without
    32-bit index values, this function will need to convert all values
    to 16-bit which may incur a performance penalty and lose information.

    \sa replaceIndexes()
*/
void QGLIndexBuffer::setIndexes(const QArray<uint>& values)
{
    Q_D(QGLIndexBuffer);
    if (d->buffer.isCreated()) {
        if (d->hasIntBuffers) {
            d->buffer.bind();
            d->buffer.allocate(values.constData(), values.size() * sizeof(int));
            d->buffer.release();
            // The element type may have changed from ushort to int.
            d->elementType = GL_UNSIGNED_INT;
        } else {
            QArray<ushort> svalues = qt_qarray_uint_to_ushort(values);
            d->buffer.bind();
            d->buffer.allocate(svalues.constData(), svalues.size() * sizeof(ushort));
            d->buffer.release();
        }
    } else if (d->hasIntBuffers) {
        d->indexesInt = values;
        d->elementType = GL_UNSIGNED_INT;
        d->indexesShort = QArray<ushort>();
    } else {
        d->indexesShort = qt_qarray_uint_to_ushort(values);
        d->elementType = GL_UNSIGNED_SHORT;
        d->indexesInt = QArray<uint>();
    }
    d->indexCount = values.size();
}
示例#27
0
    void ensureCatArray()
    {
  if ( mCat.count() > 0 || mCatList.count()==0 )
      return;

  Categories cat( 0 );
  cat.load( categoryFileName() );
  mCat.resize( mCatList.count() );
  int i;
  QStringList::ConstIterator it;
  for ( i = 0, it = mCatList.begin(); it != mCatList.end();
        ++it, i++ ) {

      bool number;
      int id = (*it).toInt( &number );
      if ( !number ) {
    id = cat.id( "Document View", *it );
    if ( id == 0 )
        id = cat.addCategory( "Document View", *it );
      }
      mCat[i] = id;
  }
    }
示例#28
0
QColor QGLContext::overlayTransparentColor() const
{
    //### make more efficient using the transpColor member
    if ( isValid() ) {
	if ( !trans_colors_init )
	    find_trans_colors();
    
	VisualID myVisualId = ((XVisualInfo*)vi)->visualid;
	for ( int i = 0; i < (int)trans_colors.size(); i++ ) {
	    if ( trans_colors[i].vis == myVisualId )
		return QColor( qRgb( 1, 2, 3 ), trans_colors[i].color );
	}
    }
    return QColor();		// Invalid color
}
示例#29
0
void BrainView::genSurfacePerVertex()
{
    if(m_SurfaceSet.size() == 0)
        return;

    if(m_pSceneNode)
    {
        delete m_pSceneNode;
        m_pSceneNode = NULL;
    }

    // in the constructor construct a builder on the stack
    QGLBuilder builder;

    float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures

    builder << QGL::Smooth;//QGL::Faceted;
    m_pSceneNodeBrain = builder.currentNode();

    builder.pushNode();

    //
    // get bounding box
    //
    calcBoundingBox();

    //
    // Build each surface in its separate node
    //
    QMap<qint32, Surface>::const_iterator it = m_SurfaceSet.data().constBegin();
    for (it = m_SurfaceSet.data().begin(); it != m_SurfaceSet.data().end(); ++it)
    {
        builder.pushNode();
        {
            Matrix3Xf rr = it.value().rr().transpose();

            //Centralize
            for(qint32 i = 0; i < 3; ++i)
                rr.row(i) = rr.row(i).array() - (m_vecBoundingBoxCenter[i] + it.value().offset()[i]);


            QGeometryData t_GeometryDataTri;

            MatrixXf t_TriCoords = MatrixXf::Zero(3,3*(it.value().tris().rows()));
            QArray<QColor4ub> cdata;
            for(qint32 i = 0; i < it.value().tris().rows(); ++i)
            {
                for(qint32 j = 0; j < 3; ++j)
                {
                    t_TriCoords.col(i*3+j) = rr.col( it.value().tris()(i,j) );

                    if(it.value().curv()[it.value().tris()(i,j)] >= 0)
                        cdata.append(QColor( 50, 50, 50, 230));//Sulci
                    else
                        cdata.append(QColor( 200, 200, 200, 230));//Gyri
                }
            }

            t_TriCoords *= fac;
            t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() ));

            t_GeometryDataTri.appendColorArray(cdata);

            //
            //  Add triangles to current node
            //
            builder.addTriangles(t_GeometryDataTri);
        }
        // Go one level up
        builder.popNode();
    }

    m_bRenderPerVertex = true;

    // Optimze current scene for display and calculate lightning normals
    m_pSceneNode = builder.finalizedSceneNode();

    m_pSceneNode->setParent(this);
}
示例#30
0
文件: ply_loader.cpp 项目: acfr/snark
PlyLoader::PlyLoader( const std::string& file, boost::optional< QColor4ub > color, double scale ) : color_( color ), scale_( scale )
{
    std::ifstream stream( file.c_str() );
    std::string line;
    std::getline( stream, line );
    if( line != "ply" ) { COMMA_THROW( comma::exception, "expected ply file; got \"" << line << "\" in " << file ); }
    unsigned int numVertex = 0;
    unsigned int numFace = 0;
    bool has_normals = false;

    std::vector< std::string > fields;
    while( stream.good() && !stream.eof() && line != "end_header" )
    {
        std::getline( stream, line );
        if( line.empty() ) { continue; }
        std::vector< std::string > v = comma::split( comma::strip( line ), ' ' );
        if( v[0] == "element" ) // quick and dirty
        {
            if( v[1] == "vertex" ) { numVertex = boost::lexical_cast< unsigned int >( v[2] ); }
            else if( v[1] == "face" ) { numFace = boost::lexical_cast< unsigned int >( v[2] ); }
        }
        else if( v[0] == "format" && v[1] != "ascii" ) { COMMA_THROW( comma::exception, "only ascii supported; got: " << v[1] ); }
        else if( line == "property float x" ) { fields.push_back( "point/x" ); }
        else if( line == "property float y" ) { fields.push_back( "point/y" ); }
        else if( line == "property float z" ) { fields.push_back( "point/z" ); }
        else if( line == "property float nx" ) { fields.push_back( "normal/x" ); has_normals = true; }
        else if( line == "property float ny" ) { fields.push_back( "normal/y" ); }
        else if( line == "property float nz" ) { fields.push_back( "normal/z" ); }
        else if( line == "property uchar red" ) { fields.push_back( "r" ); }
        else if( line == "property uchar green" ) { fields.push_back( "g" ); }
        else if( line == "property uchar blue" ) { fields.push_back( "b" ); }
        else if( line == "property uchar alpha" ) { fields.push_back( "a" ); }
    }
    comma::csv::options csv;
    csv.fields = comma::join( fields, ',' );
    csv.full_xpath = true;
    csv.delimiter = ' ';
    comma::csv::ascii< ply_vertex > ascii( csv );
    QGeometryData geometry;
    QArray< QVector3D > vertices;
    QArray< QColor4ub > colors;

    for( unsigned int i = 0; i < numVertex; i++ )
    {
        std::string s;
        if( stream.eof() ) { break; }
        std::getline( stream, s );
        if( s.empty() ) { continue; }
        ply_vertex v;
        if( color_ ) { v.color = *color_; } // quick and dirty
        ascii.get( v, s );
        if( numFace > 0 )
        {
            geometry.appendVertex( QVector3D( v.point.x() * scale_, v.point.y() * scale_, v.point.z() * scale_ ) );
            if( has_normals ) { geometry.appendNormal( QVector3D( v.normal.x(), v.normal.y(), v.normal.z() ) ); }
            geometry.appendColor( v.color );
        }
        else
        {
            vertices.append( QVector3D( v.point.x() * scale_, v.point.y() * scale_, v.point.z() * scale_ ) );
            // todo: normals?
            colors.append( v.color );
        }
    }
    if( numFace > 0 )
    {
        for( unsigned int i = 0; i < numFace; i++ ) // quick and dirty
        {
            std::string s;
            if( stream.eof() ) { break; }
            std::getline( stream, s );
            if( s.empty() ) { continue; }
            std::vector< std::string > v = comma::split( comma::strip( s ), ' ' );
            unsigned int vertices_per_face = boost::lexical_cast< unsigned int >( v[0] );
            if( ( vertices_per_face + 1 ) != v.size() ) { COMMA_THROW( comma::exception, "invalid line \"" << s << "\"" ); }
            QGL::IndexArray indices;
            switch( vertices_per_face )
            {
                case 3:
                    for( unsigned int i = 0; i < 3; ++i ) { indices.append( boost::lexical_cast< unsigned int >( v[i+1] ) ); }
                    break;
                case 4: // quick and dirty for now: triangulate
                    boost::array< unsigned int, 4 > a;
                    for( unsigned int i = 0; i < 4; ++i ) { a[i] = boost::lexical_cast< unsigned int >( v[i+1] ); }
                    indices.append( a[0] );
                    indices.append( a[1] );
                    indices.append( a[2] );
                    indices.append( a[0] );
                    indices.append( a[2] );
                    indices.append( a[3] );
                    break;
                default: // never here
                    break;
            }
            geometry.appendIndices( indices );
        }
        QGLBuilder builder;
        builder.addTriangles( geometry );
        //switch( vertices_per_face )
        //{
        //    case 3: builder.addTriangles( geometry ); break;
        //   case 4: builder.addQuads( geometry ); break;
        //  default: COMMA_THROW( comma::exception, "only triangles and quads supported; but got " << vertices_per_face << " vertices per face" );
        //}
        m_sceneNode = builder.finalizedSceneNode();
    }
    else
    {
        m_vertices.addAttribute( QGL::Position, vertices );
        // todo: normals?
        m_vertices.addAttribute( QGL::Color, colors );
        m_vertices.upload();
        m_sceneNode = NULL;
    }
    stream.close();
}