Example #1
0
// Prints an INT value to the screen
void integerprint(char x, char y, int color, int background, int integer, char size) {
    unsigned char tenthousands = 0;
    unsigned char thousands = 0;
    unsigned char hundreds = 0;
    unsigned char tens = 0;
    unsigned char ones = 0;
    if (integer >= 10000) {
        tenthousands = integer / 10000;
        ASCII(x, y, color, background, tenthousands + 48, size);
    }
    if (integer >= 1000) {
        thousands = ((integer - tenthousands * 10000)) / 1000;
        x += 6;
        ASCII(x, y, color, background, thousands + 48, size);
    }
    if (integer >= 100) {
        hundreds = (((integer - tenthousands * 10000) - thousands * 1000) - 1) / 100;
        x += 6;
        ASCII(x, y, color, background, hundreds + 48, size);
    }
    if (integer >= 10) {
        tens = (integer % 100) / 10;
        x += 6;
        ASCII(x, y, color, background, tens + 48, size);
    }
    ones = integer % 10;
    x += 6;
    ASCII(x, y, color, background, ones + 48, size);
}
AbstractObjectPtr
ObjectFactory::createObject(
    const QString &aName,
    const Position aPosition,
    const qreal aWidth,
    const qreal anHeight)
{
    const ObjectFactory *myFactoryPtr = theFactoryListPtr->getFactoryPtr(aName);
    DEBUG5("ObjectFactory::createObject(\"%s\") Factory=%p", ASCII(aName), myFactoryPtr);
    if (myFactoryPtr == nullptr) {
        DEBUG1("There is no factory for Object type '%s'", ASCII(aName));
        return nullptr;
    }
    AbstractObject *myObjectPtr = myFactoryPtr->createObject();
    assert (myObjectPtr != nullptr);
    AbstractObjectPtr mySharedOPtr = AbstractObjectPtr(myObjectPtr);
    myObjectPtr->theThisPtr = mySharedOPtr;
    DEBUG5("  object created = %p, i18n name = '%s'", myObjectPtr, ASCII(myObjectPtr->getName()));
    assert (aName.contains(" ") == false);
    myObjectPtr->theInternalName = aName;
    myObjectPtr->theCenter = aPosition;
    if (aWidth != 1.0)
        myObjectPtr->theWidth = aWidth;
    if (anHeight != 1.0)
        myObjectPtr->theHeight = anHeight;
    // finally, get rid of the actual pointer and return the shared_ptr
    assert (nullptr != mySharedOPtr);
    return mySharedOPtr;
}
Example #3
0
void Singleton::Translator::setLanguageGettext(const QString &aLocale)
{
    bindtextdomain("tbe_levels", ASCII(theBaseTbeQtLocation));
    textdomain( "tbe_levels");
    // because putenv 'eats' the memory, strdup myBuffer before putenv'ing it
    char myBuffer[255];
    snprintf(myBuffer, 254, "LANGUAGE=%s", ASCII(aLocale));
    putenv(strdup(myBuffer));
}
Example #4
0
void PropertyList::list(void) const
{
    DEBUG1("DEBUGGING: Requested listing of properties for object");
    PropertyMap::const_iterator myI = theProperties.begin();
    while (myI != theProperties.end()) {
        char myBuffer[256];
        strncpy (myBuffer, ASCII(myI.key()), 255);
        DEBUG1("  '%s' = '%s'", myBuffer, ASCII(myI.value()));
        ++myI;
    }
}
Hint *
HintSerializer::createObjectFromDom(const QDomNode &q)
{
    QString myValue;

    /// simple sanity check first...
    if (q.nodeName() != theHintString) {
        DEBUG2("createHintFromDom: expected <%s> but got <%s>", ASCII(theHintString), ASCII(q.nodeName()));
        return nullptr;
    }

    Hint *myHPtr = new Hint();

    // the nodemap contains all the attributes...
    QDomNamedNodeMap myNodeMap = q.attributes();

    for (int i = 0; i < myNodeMap.length(); i++) {
        QString myAName  = myNodeMap.item(i).nodeName();
        QString myAValue = myNodeMap.item(i).nodeValue();
        DEBUG5("  hint attribute: name %s", ASCII(myAName));
        DEBUG5("  hint attribute: value %s", ASCII(myAValue));

        if (theNumberString == myAName) {
            myHPtr->theHintIndex = myAValue.toInt();
            continue;
        }
        if (theObjectString == myAName) {
            myHPtr->theObjectName = myAValue;
            continue;
        }
        myHPtr->theParams.setProperty(myAName, myAValue);
    }

    // sanity checks:
    if (myHPtr->theHintIndex == 0 || myHPtr->theObjectName == "-") {
        DEBUG2("Hint parsing failed: mandatory field(s) missing");
        goto not_good;
    }
    if (myHPtr->theParams.getPropertyCount() == 0) {
        DEBUG2("Hint parsing failed: no parameter fields, that's just wrong");
        goto not_good;
    }

    DEBUG4("createHintFromDom %d for '%s' successful", myHPtr->theHintIndex,
           ASCII(myHPtr->theObjectName));
    return myHPtr;
not_good:
    delete myHPtr;
    return nullptr;
}
void GameState::onEntry ( QEvent *event )
{
    DEBUG4("GameControls-GameState %s onEntry!", ASCII(theName));
    QState::onEntry(event);
    isActive = true;
    emit activated(this);
}
Example #7
0
File: cartio.c Project: d-a-v/if2a
void print_array_dual (const unsigned char* array, int size)
{
	// prints contents of an array
	
	int idx;
	int block;

	#define NBLOCKS 4
	size /= sizeof(u_int32_t);
	for (block = 0; block < size; block += NBLOCKS)
	{
		char ascii4[6];
		char ascii[128] = { 0, };
		for (idx = block; idx < block + NBLOCKS; idx++)
		{
			#define H(v) ((unsigned char)(v))
			// reads 32 bits word numbered idx and converts it to host endian format if necessary
			// (assuming gba/arm's endianness is little-endian like network's convention)
			u_int32_t v;
			if (idx < size)
				v = ntoh32(((u_int32_t*)array)[idx]);
			else
				v = 0xffffffff;
		
			// print big endian first
			print("%02x %02x %02x %02x - ", H(v), H(v>>8), H(v>>16), H(v>>24));
			sprintf(ascii4, "%c%c%c%c ", ASCII(v), ASCII(v>>8), ASCII(v>>16), ASCII(v>>24));
			strcat(ascii, ascii4);
		}
		print("%s\n", ascii);
	}
}
Example #8
0
bool Singleton::Translator::setLanguage(const QString &aLocale)
{
    // ***
    // *** Only use the part up to the first space
    // ***
    QString myLocale = aLocale.section(' ', 0, 0);
    DEBUG2("Singleton::Translator::setLanguage for locale '%s'", ASCII(myLocale));

    // ***
    // *** For strings from TBE
    // ***
    if (!attemptTbeQtTranslatorLoad("", myLocale))
        if (!attemptTbeQtTranslatorLoad("./", myLocale))
            attemptTbeQtTranslatorLoad(I18N_DIRECTORY + "/", myLocale);
    if (theTbeQtTranslator.isEmpty()) {
        DEBUG1("NOTE: translator for TBE is empty");
    } else
        QCoreApplication::instance()->installTranslator(&theTbeQtTranslator);

    // ***
    // *** For strings from Qt itself
    // ***
    setLanguageQtIself(myLocale);

    // ***
    // *** For strings from our XML Levels (gettext):
    // ***
    setLanguageGettext(myLocale);

    // We're going through all the motions, but the only thing that we count
    // is whether the UI got translated...
    return !theTbeQtTranslator.isEmpty();
}
Example #9
0
File: i7k.c Project: boris-r-v/RIO
/**********************************************************************
 *  _i7k_gum_chksum
 *
 *  transfer integer chksum value to two bytes ASCII
 *  then gum it with CR (0x0d) to the given command string
 *
 *  Arguments:
 *    cbuf     the size of buffer must > strlen(cmd)+4
 *    cmd      command string with ASCIIZ format
 *
 *  Returned:  a point to cbuf
 *
 **********************************************************************/
char *_i7k_gum_chksum(void *cbuf, const char *cmd)
{
	char cL, cH;
	char *p;
	const char *q;
	unsigned int chksum;

	p = cbuf;
	q = cmd;
	chksum = 0;

	while ((*q != 0) && (*q != ASCII_CR) && (*q != ASCII_LF)) {	/* copy
																   * string */
		chksum += *q;
		*p++ = *q++;
	}
	PDEBUG("_i7k_gum_chksum: check-sum = 0x%x\n", chksum);

	cL = ASCII(chksum & 0xf);
	cH = ASCII((chksum >> 4) & 0xf);

	*p++ = cH;
	*p++ = cL;
	*p++ = ASCII_CR;
	*p = 0;

	return (cbuf);
}
Example #10
0
File: i7k.c Project: boris-r-v/RIO
/**********************************************************************
 *  _i7k_chksum
 *
 *  test the check-sum of i7k command or received string
 *  string must has tail of ASCII_CR or ASCII_LF, or 0
 *
 *  Arguments:
 *    str      string to test check-sum
 *
 *  Returned:  0 ok, -1 check-sum error!
 *
 **********************************************************************/
int _i7k_chksum(const char *str)
{
	char cL, cH;
	const char *p;
	unsigned int chksum;

	p = str;
	chksum = 0;

	while ((*p != ASCII_LF) && (*p != ASCII_CR) && (*p != 0)) {
		chksum += *p++;
	}
	chksum -= *(--p);
	chksum -= *(--p);
	PDEBUG("_i7k_chksum: check-sum = 0x%x\n", chksum);

	cL = ASCII(chksum & 0xf);
	cH = ASCII((chksum >> 4) & 0xf);

	if (cH != *p++) {
		return -1;
	}
	if (cL != *p) {
		return -1;
	}

	return (0);
}
Example #11
0
int main()
{
char x;
int y, z,i=0;
    while (i=!0){
    scanf("\n%c", &x);
    ASCII(x,y,z);
    }
}
Example #12
0
static String get_hash (const String & server_id, const Vector<Byte> & secret, const Vector<Byte> & public_key) {

    MCPP::SHA1 hash;
    hash.Update(ASCII().Encode(server_id));
    hash.Update(secret);
    hash.Update(public_key);

    return hash.HexDigest();

}
Example #13
0
// Each line with size 1 should be around 8 pixels apart, font will wrap around
// the screen if it's too long
void printrs(char x, char y, int color, int background, char* message, char size) {
    while (*message) {
        ASCII(x, y, color, background, *message++, size);
        x += 6 * size;
        if (x > 120) {
            x = 0;
            y += 8 * size;
        }
    }
}
void
ObjectFactory::announceObjectType(const QString &anObjectTypeName, ObjectFactory *aThisPtr)
{
    DEBUG4("ObjectFactory::announceObjectType(\"%s\", %p)",
           ASCII(anObjectTypeName), aThisPtr);
    if (theFactoryListPtr == nullptr)
        theFactoryListPtr = new FactoryList();
    theFactoryListPtr->insert(anObjectTypeName, aThisPtr);
    aThisPtr->theFactoryName = anObjectTypeName;
}
void EditPropertyUndoCommand::undo(void)
{
    DEBUG4("EditPropertyUndoCommand::undo for '%s'", ASCII(text()));
    AbstractObjectPtr myAOPtr = theViewObjPtr->getAbstractObjectPtr();
    if (!theKey.isNull())
        myAOPtr->theProps.setProperty(theKey, theOldValue);
    else
        myAOPtr->theID = theOldID;

    AbstractUndoCommand::undo();
}
Example #16
0
// Each line with size 1 should be around 8 pixels apart, font will wrap around
// the screen if it's too long
void prints(char x, char y, int color, int background, const char messageOld[], char size) {
    const far rom char* message = (const far rom char*) messageOld;
    while (*message) {
        ASCII(x, y, color, background, *message++, size);
        x += 6 * size;
        if (x > 120) {
            x = 0;
            y += 8 * size;
        }
    }
}
Example #17
0
bool Singleton::Translator::init()
{
    DEBUG1ENTRY;
    //** Strings in source code or XML are UTF-8, make sure Qt understands
    theTextCodecPtr = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(theTextCodecPtr);

    // retrieve the locale and set it
    QString myCurrentLocaleName = QLocale::system().name();
    DEBUG1("going to set locale '%s'", ASCII(myCurrentLocaleName));
    return setLanguage(myCurrentLocaleName);
}
void EditPropertyUndoCommand::redo(void)
{
    DEBUG4("EditPropertyUndoCommand::redo for '%s'", ASCII(text()));
    AbstractObjectPtr myAOPtr = theViewObjPtr->getAbstractObjectPtr();
    if (!theKey.isNull())
        myAOPtr->theProps.setProperty(theKey, theNewValue);
    else
        myAOPtr->theID = theNewID;

    // our parent also has to do some things...
    AbstractUndoCommand::redo();
}
ViewResizeRotateMoveUndo::~ViewResizeRotateMoveUndo()
{
    // check if we're being deleted because the parent ends...
    if (nullptr==ViewWorldItem::me())
        return;
    // if not, we're probably up for an undo commit...
    if (theUndoPtr) {
        DEBUG3("ViewResizeRotateMoveUndo::~ViewResizeRotateMoveUndo(), but still unfinished undo present.");
        DEBUG3("  this is common: it likely didn't get completed yet.")
        DEBUG3("  theUndoPtr: %p, name: '%s'.", theUndoPtr, ASCII(theUndoPtr->text()));
        commitChanges();
    }
}
Example #20
0
bool Singleton::Translator::attemptTbeQtTranslatorLoad(
    const QString &aPath,
    const QString &aLocale)
{
    QString myLocation = aPath + "tbe_" + aLocale;
    DEBUG3("Attemp: load translator from %s", ASCII(myLocation));
    if (theTbeQtTranslator.load(myLocation)) {
        DEBUG3("   ... success");
        theBaseTbeQtLocation = aPath;
        return true;
    } else {
        DEBUG3("   ... fail");
        return false;
    }
}
bool SaveLevelInfo::performFileExists(const QString &aFileName)
{
    if (isUserOKOverwritingFile == true)
        return true;

    if (QFile::exists(aFileName)) {
        DEBUG5("File '%s' already exists!", ASCII(aFileName) );
        if (Popup::YesNoQuestion(tr("A File with name '%1' file already exists. Overwrite?\n").arg(
                                     aFileName),
                                 this) == false)
            return false;
        isUserOKOverwritingFile = true;
    }
    return true;
}
SaveLevelInfo::SaveLevelInfo(Level *aLevelPtr, QWidget *parent)
    : QDialog(parent), theLevelPtr(aLevelPtr)
{
    isUserOKOverwritingFile = false;

    ui.setupUi(this);
    ui.theFileNameField        ->setText(theLevelPtr->getLevelFileName());
    ui.theAuthorNameField      ->setText(theLevelPtr->theLevelAuthor);
    ui.theLevelDescriptionField->setText(theLevelPtr->theLevelDescription);
    ui.theLicenseField         ->setText(theLevelPtr->theLevelLicense);
    ui.theTitleField           ->setText(theLevelPtr->theLevelName);

    QDate myDate = QDate::fromString(theLevelPtr->theLevelDate);
    if (myDate.isValid())
        ui.theDateEdit->setDate(myDate);
    else {
        DEBUG5("SaveLevelInfo::SaveLevelInfo - Date '%s' is not understood, setting to current date",
               ASCII(theLevelPtr->theLevelDate));
        ui.theDateEdit->setDate(QDate::currentDate());
    }

    connect(ui.theFileNameField, SIGNAL(textEdited(const QString &)), this, SLOT(fileNameChanged()));
}
Example #23
0
static void	add(char *s1, char *s2)
{
  char *a, *b, *c;
  int la, lb, len;
  int i, j;
  int carry;
  int add;

  a = BIGGEST(s1, s2);
  b = SMALLEST(s1, s2);
  la = strlen(a);
  lb = strlen(b);
  len = la + 1;
  if (!(c = memset(malloc((len  + 1) * sizeof(char)), '0', len)))
    return ;
  c[len] = 0;
  for (i = la - 1, j = lb - 1, carry = 0; i >= IS_NEG(a); --i, --j)
    {
      if (IS_NEG(a) == IS_NEG(b))
	{
	  add = ALIGN(a, i) + ALIGN(b, j) + carry;
	  carry = add / 10;
	}
      else
	{
	  add = ALIGN(a, i) - ALIGN(b, j) - carry;
	  carry = (add < 0);
	  add = POS(add);
	}
      c[i + 1] = ASCII(POS(add % 10));
    }
  if (IS_NEG(a) && (a != SMALLEST(b, a)
		    || IS_NEG(b)))
    printf("-");
  print_nb(c);
  free(c);
}
Example #24
0
void processKeyboard(GlobalState* globalData, char* name, int size) {
    static short pos[] = {0, 0};
    static short letters = 0;

    if (globalData->newKeyboard == 1) {
        globalData->newKeyboard = 0;
        pos[0] = 0;
        pos[1] = 0;
        letters = 0;
    } else {

        switch (globalData->keyPress) {
            case 0x08:
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, " ", 1);
                if (pos[1] < 2) {
                    pos[1]++;
                }
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, ">", 1);
                break;
            case 0x02:
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, " ", 1);
                if (pos[1] > 0) {
                    pos[1]--;
                }
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, ">", 1);
                break;
            case 0x04:
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, " ", 1);
                if (pos[0] > 0) {
                    pos[0]--;
                }
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, ">", 1);
                break;
            case 0x06:
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, " ", 1);
                if (pos[0] < 9) {
                    pos[0]++;
                }
                prints(3 + 12 * pos[0], 10 * pos[1] + 23, WHITE, BLUE, ">", 1);
                break;
            case 0x0D:
                if (letters < size - 1) {
                    name[letters] = (char) (65 + pos[0] + 10 * pos[1]);
                    name[letters + 1] = '\0';
                    ASCII(6 + 12 * letters, 8, WHITE, BLUE, name[letters], 1);
                    letters = letters + 1;
                    if (letters == size - 1) {
                        prints(42 + 12 * 5, 0, WHITE, BLUE, "end", 1);
                    }
                }
                break;
            case 0x0B:
                if (letters > 0) {
                    if (letters == size - 1) {
                        prints(42 + 12 * 5, 0, WHITE, BLUE, "   ", 1);
                    }
                    letters--;
                    ASCII(6 + 12 * letters, 8, WHITE, BLUE, '_', 1);
                    name[letters] = '\0';
                }
                break;
            case 0x0F:
                globalData->doneKeyboard = 1;
                globalData->newKeyboard = 1;
                break;
        }

    }
}
    void PoissonReconstruction::PoissonRecon(int argc , char* argv[], const MagicDGP::Point3DSet* pPC, std::vector< PlyValueVertex< float > >& vertices, std::vector< std::vector< int > >& polygons)
    {
        cmdLineString
            In( "in" ) ,
            Out( "out" ) ,
            VoxelGrid( "voxel" ) ,
            XForm( "xForm" );

        cmdLineReadable
            Performance( "performance" ) ,
            ShowResidual( "showResidual" ) ,
            NoComments( "noComments" ) ,
            PolygonMesh( "polygonMesh" ) ,
            Confidence( "confidence" ) ,
            NonManifold( "nonManifold" ) ,
            ASCII( "ascii" ) ,
            Density( "density" ) ,
            Verbose( "verbose" );

        cmdLineInt
            Depth( "depth" , 8 ) ,
            SolverDivide( "solverDivide" , 8 ) ,
            IsoDivide( "isoDivide" , 8 ) ,
            KernelDepth( "kernelDepth" ) ,
            AdaptiveExponent( "adaptiveExp" , 1 ) ,
            MinIters( "minIters" , 24 ) ,
            FixedIters( "iters" , -1 ) ,
            VoxelDepth( "voxelDepth" , -1 ) ,
            MinDepth( "minDepth" , 5 ) ,
            MaxSolveDepth( "maxSolveDepth" ) ,
            BoundaryType( "boundary" , 1 ) ,
            Threads( "threads" , omp_get_num_procs() );

        cmdLineFloat
            SamplesPerNode( "samplesPerNode" , 1.f ) ,
            Scale( "scale" , 1.1f ) ,
            SolverAccuracy( "accuracy" , float(1e-3) ) ,
            PointWeight( "pointWeight" , 4.f );

        cmdLineReadable* params[] =
        {
            &In , &Depth , &Out , &XForm ,
            &SolverDivide , &IsoDivide , &Scale , &Verbose , &SolverAccuracy , &NoComments ,
            &KernelDepth , &SamplesPerNode , &Confidence , &NonManifold , &PolygonMesh , &ASCII , &ShowResidual , &MinIters , &FixedIters , &VoxelDepth ,
            &PointWeight , &VoxelGrid , &Threads , &MinDepth , &MaxSolveDepth ,
            &AdaptiveExponent , &BoundaryType ,
            &Density
        };

        cmdLineParse( argc , argv , sizeof(params)/sizeof(cmdLineReadable*) , params , 1 );
        /*if( Density.set ) 
            return Execute< 2 , PlyValueVertex< Real > , true  >(argc , argv, pPC);
        else       
            return Execute< 2 ,      PlyVertex< Real > , false >(argc , argv, pPC);*/
        //Execute
        int i;
        int paramNum = sizeof(params)/sizeof(cmdLineReadable*);
        int commentNum=0;
        char **comments;

        comments = new char*[paramNum + 7];
        for( i=0 ; i<paramNum+7 ; i++ ) comments[i] = new char[1024];

        //if( Verbose.set ) echoStdout=1;

        XForm4x4< Real > xForm , iXForm;
        if( XForm.set )
        {
            FILE* fp = fopen( XForm.value , "r" );
            if( !fp )
            {
                fprintf( stderr , "[WARNING] Could not read x-form from: %s\n" , XForm.value );
                xForm = XForm4x4< Real >::Identity();
            }
            else
            {
                for( int i=0 ; i<4 ; i++ ) for( int j=0 ; j<4 ; j++ ) fscanf( fp , " %f " , &xForm( i , j ) );
                fclose( fp );
            }
        }
        else xForm = XForm4x4< Real >::Identity();
        iXForm = xForm.inverse();

        //DumpOutput2( comments[commentNum++] , "Running Screened Poisson Reconstruction (Version 5.0)\n" , Degree );
        //char str[1024];
        //for( int i=0 ; i<paramNum ; i++ )
        //    if( params[i]->set )
        //    {
        //        params[i]->writeValue( str );
        //        if( strlen( str ) ) DumpOutput2( comments[commentNum++] , "\t--%s %s\n" , params[i]->name , str );
        //        else                DumpOutput2( comments[commentNum++] , "\t--%s\n" , params[i]->name );
        //    }

        double t;
        double tt=Time();
        Real isoValue = 0;

        //Octree< Degree , OutputDensity > tree;
        Octree< 2 , true > tree;
        tree.threads = Threads.value;
        //if( !In.set )
        //{
        //    ShowUsage(argv[0]);
        //    return 0;
        //}
        if( !MaxSolveDepth.set ) MaxSolveDepth.value = Depth.value;
        if( SolverDivide.value<MinDepth.value )
        {
            fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , SolverDivide.name , MinDepth.name , SolverDivide.value , MinDepth.value );
            SolverDivide.value = MinDepth.value;
        }
        if( IsoDivide.value<MinDepth.value )
        {
	        fprintf( stderr , "[WARNING] %s must be at least as large as %s: %d>=%d\n" , IsoDivide.name , MinDepth.name , IsoDivide.value , IsoDivide.value );
	        IsoDivide.value = MinDepth.value;
        }
	
        OctNode< TreeNodeData< true > , Real >::SetAllocator( MEMORY_ALLOCATOR_BLOCK_SIZE );

        t=Time();
        int kernelDepth = KernelDepth.set ?  KernelDepth.value : Depth.value-2;

        tree.setBSplineData( Depth.value , BoundaryType.value );
        //if( kernelDepth>Depth.value )
        //{
        //    fprintf( stderr,"[ERROR] %s can't be greater than %s: %d <= %d\n" , KernelDepth.name , Depth.name , KernelDepth.value , Depth.value );
        //    return EXIT_FAILURE;
        //}
        //
        int pointNumber = pPC->GetPointNumber();
        std::vector<float> posList(pointNumber * 3);
        std::vector<float> norList(pointNumber * 3);
        for (int pIndex = 0; pIndex < pointNumber; pIndex++)
        {
            posList.at(3 * pIndex + 0) = pPC->GetPoint(pIndex)->GetPosition()[0];
            posList.at(3 * pIndex + 1) = pPC->GetPoint(pIndex)->GetPosition()[1];
            posList.at(3 * pIndex + 2) = pPC->GetPoint(pIndex)->GetPosition()[2];
            norList.at(3 * pIndex + 0) = pPC->GetPoint(pIndex)->GetNormal()[0];
            norList.at(3 * pIndex + 1) = pPC->GetPoint(pIndex)->GetNormal()[1];
            norList.at(3 * pIndex + 2) = pPC->GetPoint(pIndex)->GetNormal()[2];
        }
        //
        double maxMemoryUsage;
        t=Time() , tree.maxMemoryUsage=0;
        //int pointCount = tree.setTree( In.value , Depth.value , MinDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , PointWeight.value , AdaptiveExponent.value , xForm );
        int pointCount = tree.setTree( posList, norList, Depth.value , MinDepth.value , kernelDepth , Real(SamplesPerNode.value) , Scale.value , Confidence.set , PointWeight.value , AdaptiveExponent.value , xForm );
        tree.ClipTree();
        tree.finalize( IsoDivide.value );

        /*DumpOutput2( comments[commentNum++] , "#             Tree set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
        DumpOutput( "Input Points: %d\n" , pointCount );
        DumpOutput( "Leaves/Nodes: %d/%d\n" , tree.tree.leaves() , tree.tree.nodes() );
        DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );*/

        maxMemoryUsage = tree.maxMemoryUsage;
        t=Time() , tree.maxMemoryUsage=0;
        tree.SetLaplacianConstraints();
        /*DumpOutput2( comments[commentNum++] , "#      Constraints set in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
        DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage())/(1<<20) );*/
        maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

        t=Time() , tree.maxMemoryUsage=0;
        tree.LaplacianMatrixIteration( SolverDivide.value, ShowResidual.set , MinIters.value , SolverAccuracy.value , MaxSolveDepth.value , FixedIters.value );
        /*DumpOutput2( comments[commentNum++] , "# Linear system solved in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
        DumpOutput( "Memory Usage: %.3f MB\n" , float( MemoryInfo::Usage() )/(1<<20) );*/
        maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );

        CoredFileMeshData< PlyValueVertex< Real > > mesh;

        if( Verbose.set ) tree.maxMemoryUsage=0;
        t=Time();
        isoValue = tree.GetIsoValue();
        //DumpOutput( "Got average in: %f\n" , Time()-t );
        //DumpOutput( "Iso-Value: %e\n" , isoValue );

        if( VoxelGrid.set )
        {
            double t = Time();
            FILE* fp = fopen( VoxelGrid.value , "wb" );
            if( !fp ) fprintf( stderr , "Failed to open voxel file for writing: %s\n" , VoxelGrid.value );
            else
            {
                int res;
                Pointer( Real ) values = tree.GetSolutionGrid( res , isoValue , VoxelDepth.value );
                fwrite( &res , sizeof(int) , 1 , fp );
                if( sizeof(Real)==sizeof(float) ) fwrite( values , sizeof(float) , res*res*res , fp );
                else
                {
                    float *fValues = new float[res*res*res];
                    for( int i=0 ; i<res*res*res ; i++ ) fValues[i] = float( values[i] );
                    fwrite( fValues , sizeof(float) , res*res*res , fp );
                    delete[] fValues;
                }
                fclose( fp );
                DeletePointer( values );
            }
            //DumpOutput( "Got voxel grid in: %f\n" , Time()-t );
        }

        if( Out.set )
        {
            t = Time() , tree.maxMemoryUsage = 0;
            tree.GetMCIsoTriangles( isoValue , IsoDivide.value , &mesh , 0 , 1 , !NonManifold.set , PolygonMesh.set );
            //if( PolygonMesh.set ) DumpOutput2( comments[commentNum++] , "#         Got polygons in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
            //else                  DumpOutput2( comments[commentNum++] , "#        Got triangles in: %9.1f (s), %9.1f (MB)\n" , Time()-t , tree.maxMemoryUsage );
            maxMemoryUsage = std::max< double >( maxMemoryUsage , tree.maxMemoryUsage );
            //DumpOutput2( comments[commentNum++],"#             Total Solve: %9.1f (s), %9.1f (MB)\n" , Time()-tt , maxMemoryUsage );

            //if( NoComments.set )
            //{
            //    if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII         , NULL , 0 , iXForm );
            //    else            PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , NULL , 0 , iXForm );
            //}
            //else
            //{
            //    if( ASCII.set ) PlyWritePolygons( Out.value , &mesh , PLY_ASCII         , comments , commentNum , iXForm );
            //    else            PlyWritePolygons( Out.value , &mesh , PLY_BINARY_NATIVE , comments , commentNum , iXForm );
            //}
            vertices.clear();
            polygons.clear();
            int incorePointNum = int( mesh.inCorePoints.size() );
            int outofcorePointNum = mesh.outOfCorePointCount();
            DebugLog << "incorePointNum: " << incorePointNum << std::endl;
            DebugLog << "outofcorePointNum: " << outofcorePointNum << std::endl;
            mesh.resetIterator();
            for(int pIndex = 0 ; pIndex < incorePointNum ; pIndex++ )
            {
                PlyValueVertex< Real > vertex = iXForm * mesh.inCorePoints[pIndex];
                vertices.push_back(vertex);
                //ply_put_element(ply, (void *) &vertex);
            }
            for(int pIndex = 0; pIndex < outofcorePointNum; pIndex++ )
            {
                PlyValueVertex< Real > vertex;
                mesh.nextOutOfCorePoint( vertex );
                vertex = iXForm * ( vertex );
                vertices.push_back(vertex);
                //ply_put_element(ply, (void *) &vertex);
            }
            int polyNum = mesh.polygonCount();
            DebugLog << "polyNum: " << polyNum << std::endl;
            for (int pIndex = 0; pIndex < polyNum; pIndex++)
            {
                std::vector< CoredVertexIndex > coreIndex;
                mesh.nextPolygon(coreIndex);
                std::vector< int > pureIndex;
                for (int ii = 0; ii < coreIndex.size(); ii++)
                {
                    if (coreIndex.at(ii).inCore)
                    {
                        pureIndex.push_back(coreIndex.at(ii).idx);
                    }
                    else
                    {
                        pureIndex.push_back(coreIndex.at(ii).idx + incorePointNum);
                    }
                }
                if (coreIndex.size() != 3)
                {
                    DebugLog << "Error: coreIndex.size: " << coreIndex.size() << std::endl;
                }
                polygons.push_back(pureIndex);
            }
            //just for test
            /*DebugLog << "Export inter object" << std::endl;
            std::ofstream fout("pc_inter.obj");
            for (int pIndex = 0; pIndex < vertices.size(); pIndex++)
            {
                PlyValueVertex< float > vert = vertices.at(pIndex);
                fout << "v " << vert.point[0] << " " << vert.point[1] << " " << vert.point[2] << std::endl;
            }
            for (int pIndex = 0; pIndex < polygons.size(); pIndex++)
            {
                fout << "f " << polygons.at(pIndex).at(0) + 1 << " " << polygons.at(pIndex).at(1) + 1 << " " << polygons.at(pIndex).at(2) + 1 << std::endl;
            }
            fout.close();*/
        }
    }
Example #26
0
void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;                // Stop the watchdog
    __enable_interrupt();                    // Enable general interrupts
    Board_init();                            // Configure's the F5529 EXP board's I/Os
    
    // Initialize power/clocks for use with USB
    SetVCore(3);                             // The USB module requires that VCore be set to highest setting, independent of MCLK freq
    ClockUSB();
    
    disk_initialize(0);                      // SD-cards must go through a setup sequence after powerup.  This FatFs call does this.  
    USB_init();                              // Initializes the USB API, and prepares the USB module to detect USB insertion/removal events
    USB_setEnabledEvents(kUSB_allUsbEvents); // Enable all USB events
      
    // The data interchange buffer (used when handling SCSI READ/WRITE) is declared by the application, and 
    // registered with the API using this function.  This allows it to be assigned dynamically, giving 
    // the application more control over memory management.  
    USBMSC_registerBufInfo(&RW_dataBuf[0], NULL, sizeof(RW_dataBuf));
 
    
    // The API maintains an instance of the USBMSC_RWbuf_Info structure.  If double-buffering were used, it would
    // maintain one for both the X and Y side.  (This version of the API only supports single-buffering,
    // so only one structure is maintained.)  This is a shared resource between the API and application; the 
    // application must request the pointers.    
    RWbuf_info = USBMSC_fetchInfoStruct();
  
    
    // USBMSC_updateMediaInfo() must be called prior to USB connection.  We check if the card is present, and if so, pull its size
    // and bytes per block.  
    // LUN0
    mediaInfo.mediaPresent = 0x01;        // The medium is present, because internal flash is non-removable.  
    mediaInfo.mediaChanged = 0x00;        // It can't change, because it's in internal memory, which is always present.  
    mediaInfo.writeProtected = 0x00;      // It's not write-protected
    mediaInfo.lastBlockLba = 774;         // 774 blocks in the volume. (This number is also found twice in the volume itself; see mscFseData.c. They should match.)
    mediaInfo.bytesPerBlock = BYTES_PER_BLOCK; // 512 bytes per block. (This number is also found in the volume itself; see mscFseData.c. They should match.)
    USBMSC_updateMediaInfo(0, &mediaInfo); 
    
    // LUN1
    if(detectCard())
      mediaInfo.mediaPresent = kUSBMSC_MEDIA_PRESENT;
    else mediaInfo.mediaPresent = kUSBMSC_MEDIA_NOT_PRESENT;
    mediaInfo.mediaChanged = 0x00;
    mediaInfo.writeProtected = 0x00;
    disk_ioctl(0,GET_SECTOR_COUNT,&mediaInfo.lastBlockLba);   // Returns the number of blocks (sectors) in the media. 
    mediaInfo.bytesPerBlock = BYTES_PER_BLOCK;                // Block size will always be 512
    USBMSC_updateMediaInfo(1, &mediaInfo); 
    
    
    // At compile-time for this demo, there will be one file on the volume.  The root directory and data cluster
    // for this file need to be initialized.  
    //flashWrite_LBA(Root_Dir, (BYTE*)Root_Dir_init); 
    //flashWrite_LBA(Data559, (BYTE*)Data559_init); 
    
    
    // Configure Timer_A0 to prompt detection of the SD card every second
    TA0CCTL0 = CCIE;                          // Enable interrupt
    TA0CCR0 = 32768;                          // Clock will be 32kHz, so we set the int to occur when it counts to 32768
    TA0CTL = TASSEL_1 + MC_1 + TACLR;         // ACLK = 32kHz, up mode, clear TAR... go!

  
    // If USB is already connected when the program starts up, then there won't be a USB_handleVbusOnEvent(). 
    // So we need to check for it, and manually connect if the host is already present.   
    if (USB_connectionInfo() & kUSB_vbusPresent)
    {
      if (USB_enable() == kUSB_succeed)
      {
        USB_reset();
        USB_connect();      
      }
    }
  
    while(1)
    {
      BYTE ReceiveError=0, SendError=0;
      WORD count;
      switch(USB_connectionState())
      {
        case ST_USB_DISCONNECTED:
                 __bis_SR_register(LPM3_bits + GIE); 	       // Enter LPM3 until VBUS-on event
                
                 // Check if the reason we woke was a button press; and if so, log a new piece of data.  
                 if(fS1ButtonEvent)
                 {
                   // Build string
                   char str[14] = "Data entry #0\n";
                   str[12] = logCnt++;                             // Number the entries 0 through....?
                   
                   memcpy(RW_dataBuf, Data559, BYTES_PER_BLOCK);  // Copy data block 559 from flash to RAM buffer
                   memcpy(&RW_dataBuf[DataCnt], str, sizeof(str)); // Write the new entry to the RAM buffer
                   flashWrite_LBA((PBYTE)Data559, RW_dataBuf);    // Copy it back to flash
                   
                   DataCnt += sizeof(str);                         // Increment the index past the new entry
                   if((DataCnt + sizeof(str)>= BYTES_PER_BLOCK))   // Roll index back to 0, if no more room in the block
                     DataCnt = 0;
        
                   fS1ButtonEvent = 0;
                 }
                break;
          
        case ST_USB_CONNECTED_NO_ENUM:
                break;
          
        case ST_ENUM_ACTIVE:             

                // Call USBMSC_poll() to initiate handling of any received SCSI commands.  Disable interrupts 
                // during this function, to avoid conflicts arising from SCSI commands being received from the host
                // AFTER decision to enter LPM is made, but BEFORE it's actually entered (in other words, avoid
                // sleeping accidentally).  
                __disable_interrupt();
                if((USBMSC_poll() == kUSBMSC_okToSleep) && (!bDetectCard))
                {
                    __bis_SR_register(LPM0_bits + GIE);  // Enable interrupts atomically with LPM0 entry
                }
                __enable_interrupt();
                
                                               
                // If the API needs the application to process a buffer, it will keep the CPU awake by returning kUSBMSC_processBuffer
                // from USBMSC_poll().  The application should then check the 'operation' field of all defined USBMSC_RWbuf_Info
                // structure instances.  If any of them is non-null, then an operation needs to be processed.  A value of 
                // kUSBMSC_READ indicates the API is waiting for the application to fetch data from the storage volume, in response 
                // to a SCSI READ command from the USB host.  After the application does this, it must indicate whether the 
                // operation succeeded, and then close the buffer operation by calling USBMSC_bufferProcessed().  
                
                while(RWbuf_info->operation == kUSBMSC_READ)
                {
                  switch(RWbuf_info->lun)
                  {
                    case 0:
                      RWbuf_info->returnCode = Read_LBA(RWbuf_info->lba, RWbuf_info->bufferAddr, RWbuf_info->lbCount); // Fetch a block from the medium, using file system emulation
                      USBMSC_bufferProcessed();                           // Close the buffer operation
                      break;
                      
                    case 1:
                      read_LUN1();
                      break;
                  }
                }
                
                // Everything in this section is analogous to READs.  Reference the comments above.   
                while(RWbuf_info->operation == kUSBMSC_WRITE)
                {                  
                  switch(RWbuf_info->lun)
                  {
                    case 0:
                      RWbuf_info->returnCode = Write_LBA(RWbuf_info->lba, RWbuf_info->bufferAddr, RWbuf_info->lbCount); // Write the block to the medium, using file system emulation
                      USBMSC_bufferProcessed();                            // Close the buffer operation
                      break;
                    case 1:
                      write_LUN1();
                      break;
                  }
                }
                
                // Every second, the Timer_A ISR sets this flag.  The checking can't be done from within the timer ISR, because the
                // checking enables interrupts, and this is not a recommended practice due to the risk of nested interrupts.  
                if(bDetectCard)
                {
                  checkInsertionRemoval();
                  bDetectCard = 0x00;                          // Clear the flag, until the next timer ISR
                }
                
                if(bHID_DataReceived_event) //Message is received from HID application
                {
                	bHID_DataReceived_event = FALSE;          // Clear flag early -- just in case execution breaks below because of an error
                	count = hidReceiveDataInBuffer((BYTE*)dataBuffer,BUFFER_SIZE,HID0_INTFNUM);
                	strncat(wholeString," \r\nRx->",7);
                    strncat(wholeString,(char*)dataBuffer,count);
                  	strncat(wholeString," \r\n ",4);
                	if(cdcSendDataInBackground((BYTE*)wholeString,strlen(wholeString),CDC0_INTFNUM,1)) // Send message to other CDC App
                	{
                		SendError = 0x01;
                		break;
                	}
                	memset(wholeString,0,MAX_STR_LENGTH);           // Clear wholeString
                }
                if(bCDC_DataReceived_event)  //Message is received from CDC application 
                {
                  bCDC_DataReceived_event = FALSE;                  // Clear flag early -- just in case execution breaks below because of an error
                  cdcReceiveDataInBuffer((BYTE*)wholeString,MAX_STR_LENGTH,CDC0_INTFNUM);
                  ASCII(wholeString);
                  if(hidSendDataInBackground((BYTE*)wholeString,strlen(wholeString),HID0_INTFNUM,1))  // Send message to HID App
                  {
                    SendError = 0x01;                          // Something went wrong -- exit
                    break;
                  }
                  memset(wholeString,0,MAX_STR_LENGTH);  // Clear wholeString
                }
                                               
                break;
                
            case ST_ENUM_SUSPENDED:
                __bis_SR_register(LPM3_bits + GIE);            // Enter LPM3, until a resume or VBUS-off event
                break;
              
          case ST_ENUM_IN_PROGRESS:
                break;
              
          case ST_ERROR:
                break;           
          default:;
      }
      if(ReceiveError || SendError)
      { 
          //TO DO: User can place code here to handle error
      }    
    }
}
Example #27
0
int isxdigit(int ch) { return ASCII(ch)? (type[ch] & XDIGIT): 0; }
Example #28
0
int isupper(int ch) { return ASCII(ch)? (type[ch] & UPPER): 0; }
Example #29
0
int isspace(int ch) { return ASCII(ch)? (type[ch] & SPACE): 0; }
Example #30
0
int ispunct(int ch) { return ASCII(ch)? (type[ch] & PUNCT): 0; }