Exemplo n.º 1
0
TEST_F(PsdFileHighLevelTest, verifyGroupCount) {

    ASSERT_EQ(PsdStatusOK, file1->open());
    ASSERT_EQ(PsdStatusOK, file2->open());

    //file1 has 0 groups
    ASSERT_EQ(3, getGroupCount(file1->getLayers()));
    //file2 has 0 groups
    ASSERT_EQ(0, getGroupCount(file2->getLayers()));
}
Exemplo n.º 2
0
    unsigned int getGroupCount(PsdLayers layers)
    {
        int groupCount = 0;
        vector<shared_ptr<PsdLayer> >::reverse_iterator iter = layers->rbegin(), end = layers->rend();
        for (; iter != end; iter++) {
            shared_ptr<PsdLayer> layer = *iter;
            if (layer.get() != NULL)
            {
                if (layer->getType() == PsdLayer::LayerTypeGroup) {
                    groupCount++;
                    groupCount += getGroupCount(((PsdLayerGroup *) layer.get())->getLayers());
                }
            }
        }

        return groupCount;
    }
Exemplo n.º 3
0
mxArray* buildGroupsArrayForTrial(DataLoggerStatus *dlStatus, unsigned trialIdx, bool clearBuffers)
{
    DataLoggerStatusByTrial* trialStatus = dlStatus->byTrial + trialIdx;

    // gtrie for current trial
    GroupTrie* gtrie = dlStatus->gtrie;

    int nFieldsGroup = 7;
    const char* fieldNames[] = {"name", "type", "configHash", "version", "signalNames", "signals", "time"};
    mxArray *mxGroups, *mxSignals;

    unsigned nGroups = getGroupCount(gtrie);
    unsigned nGroupsUsed = 0;

    // create the outer groups array
    mxGroups = mxCreateStructMatrix(nGroups, 1, nFieldsGroup, fieldNames);

    if(trialStatus->utilized) {
        // ensure trial actually used
        timestamp_t trialStartTime = trialStatus->timestampStart;

        GroupTrie* groupNode = getFirstGroupNode(gtrie);
        SignalDataBuffer* psdb;
        for(unsigned iGroup = 0; iGroup < nGroups; iGroup++) {
            if(groupNode == NULL) break;
            GroupInfo* pg = (GroupInfo*)groupNode->value;
            unsigned nSamples = pg->tsBuffers[trialIdx].nSamples;

            if(pg->tsBuffers[trialIdx].nSamples > 0) {
                unsigned iGroupInArray = nGroupsUsed;

                // build an mxArray containing meta data about this group
                setGroupMetaFields((const GroupInfo*)pg, mxGroups, iGroupInArray);

                if(pg->type == GROUP_TYPE_ANALOG) {
                    // build an mxArray containing timestamps for this group
                    // false = don't use group field name prefix
                    addGroupTimestampsField(mxGroups, (const GroupInfo*)pg, trialIdx,
                        trialStartTime, false, iGroupInArray, nSamples);
                }

                // add in the signal fields
                mxSignals = mxCreateStructMatrix(1,1,0,NULL);
                if(pg->type != GROUP_TYPE_EVENT) {
					for(unsigned iSignal = 0; iSignal < pg->nSignals; iSignal++) {
						psdb = pg->signals[iSignal];
						if(psdb == NULL) continue;
						// add the signal data to mxSignals which is groups(iGroup).signals
						addSignalDataField(mxSignals, psdb, trialIdx, false, nSamples);

						// clear the timeseries buffer as these samples are no longer needed
						if(clearBuffers)
							clearSampleBuffer(psdb->buffers + trialIdx);
					}

                } else { // event group
                    // add the events directly to mxSignals, i.e. groups(iGroup.signals),
                    // without a group prefix
                    // add the meta field group.signalNames as groups(iGroup).signalNames
                    addEventGroupFields(mxSignals, mxGroups, pg, trialIdx,
                        trialStartTime, false, iGroupInArray);
                    if(clearBuffers) {
                    	for(unsigned iSignal = 0; iSignal < pg->nSignals; iSignal++) {
                    		psdb = pg->signals[iSignal];
                    		clearSampleBuffer(psdb->buffers + trialIdx);
                    	}
                    }
                }

                // add signals to groups(i).signals
                mxSetField(mxGroups, iGroupInArray, "signals", mxSignals);

                // clear the group's timestamp buffer
                if(clearBuffers)
                    clearTimestampBuffer(pg->tsBuffers + trialIdx);

                nGroupsUsed++;
            }

            // advance to the next group
            groupNode = getNextGroupNode(groupNode);
        }
    }
    // shrink the groups array in case some groups were unused
    if(nGroupsUsed < nGroups)
        mxSetM(mxGroups, nGroupsUsed);

    // mark this trial as written if we flushed the data
    if(clearBuffers) {
        controlMarkTrialWritten(dlStatus, trialIdx);
        //logInfo("marked trial %d as written\n", trialIdx);
    }

    return mxGroups;
}