Exemplo n.º 1
0
void FaceController::saveFace()
{/*
 for (size_t i = 0, ilen= facesStoreVector.size(); i<ilen; i++)
	{
		JsonTree oneFaceJson;
		oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[i].getTexName() ) );

		JsonTree facesDataJson = JsonTree::makeArray( "data" );

		auto points =  facesStoreVector[i].getPoints();
		for (size_t j = 0, ilen = points.size() ; j < ilen; j++)
		{
			JsonTree point;
			point.addChild(JsonTree( "x",points[j].x) );	
			point.addChild(JsonTree( "y",points[j].y) );	
			facesDataJson.pushBack(point);
		}
		oneFaceJson.addChild(facesDataJson );

		facesJson.pushBack(oneFaceJson);
	}

	doc.pushBack( facesJson );
	
	writeImage( getAppPath() /FACE_STORAGE_FOLDER/genericName, surf );
	doc.write( writeFile( getAppPath() / DATA_BASE_NAME ), JsonTree::WriteOptions() );	*/

	// SAVE LAST ONLY!!!!


	JsonTree doc;
	JsonTree facesJson = JsonTree::makeArray( "faces" );

	int id = facesStoreVector.size() - 1;

	JsonTree oneFaceJson;
	oneFaceJson.addChild( JsonTree( "texname", facesStoreVector[id].getTexName() ) );

	JsonTree facesDataJson = JsonTree::makeArray( "data" );

		auto points =  facesStoreVector[id].getPoints();
		for (size_t j = 0, ilen = points.size() ; j < ilen; j++)
		{
			JsonTree point;
			point.addChild(JsonTree( "x",points[j].x) );	
			point.addChild(JsonTree( "y",points[j].y) );	
			facesDataJson.pushBack(point);
		}
	oneFaceJson.addChild(facesDataJson );
	facesJson.pushBack(oneFaceJson);

	doc.pushBack( facesJson );

	string jsonName = "base_"+to_string(id) + ".json";	
	
	
	doc.write( writeFile( getAppPath() / JSON_STORAGE_FOLDER / jsonName ), JsonTree::WriteOptions() );

}
void TextureSequenceOptimizer::saveMax( fs::path path )
{
    if ( path == fs::path() ) {
        path = app::App::get()->getFolderPath();
        app::console() << "SAVE MAX: " << path << std::endl;
    }
    if( ! path.empty() ){
        
        fs::path jsonPath = path;
        jsonPath.append("sequence.json");
        JsonTree doc = JsonTree::makeObject();
        
        JsonTree size = JsonTree::makeObject("size");
        size.pushBack(JsonTree("width",  mOriOutline.getWidth()  ));
        size.pushBack(JsonTree("height", mOriOutline.getHeight() ));
        doc.pushBack(size);
        
        JsonTree sequence = JsonTree::makeArray("sequence");
        //go thru each surface
        for (int i = 0; i < mSurfaceRefs.size(); i++) {
            fs::path tempPath = path;
            
            //only clone the non-transparent area based on the offsets
            Surface tempSurf;
            JsonTree curImage = JsonTree::makeObject();
            
            if( mTrimMaxAreas[i].calcArea() == 0 ){
                app::console() << " Image is completely transparent: " << mFileNames[i] << std::endl;
                tempPath.append("transparent.png");
                
                // check if transparent pixel exists
                if( !fs::exists(tempPath) ){
                    // create transparent png if it doesn't exist
                    tempSurf = mSurfaceRefs[i]->clone( Area(0,0,10,10) );
                    writeImage( tempPath, tempSurf );
                }
                
                // point to transparent image
                curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
                curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
                curImage.pushBack(JsonTree("fileName", "transparent.png" ));
            }else{
                tempSurf = mSurfaceRefs[i]->clone(mTrimMaxAreas[i]);
                tempPath.append(toString(mFileNames[i]));
                writeImage( tempPath, tempSurf );
                curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
                curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
                curImage.pushBack(JsonTree("fileName", mFileNames[i] ));
            }
            sequence.pushBack(curImage);
            
            //app::console() << "saving: " << tempPath << " "<< mTrimMaxAreas[i] << std::endl;
            
            tempPath.clear();
        }
        doc.pushBack(sequence);
        doc.write( jsonPath, JsonTree::WriteOptions());
        //saveJson(path);
    }
}
Exemplo n.º 3
0
void ClientApp::mouseMove( MouseEvent event )
{
	// send mouse positions to server
	JsonTree mousePositions;
	mousePositions.pushBack( JsonTree( "x", event.getX() ) );
	mousePositions.pushBack( JsonTree( "y", event.getY() ) );

	mAMPM->sendCustomMessage( "/mouse", mousePositions );
}
//! to json
JsonTree	WarpPerspectiveBilinear::toJson() const
{
	JsonTree		json = WarpBilinear::toJson();
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// set corners
		JsonTree	corners = JsonTree::makeArray("corners");
		for (unsigned i = 0; i < 4; ++i) {
			vec2 corner = mWarp->getControlPoint(i);
			JsonTree	cr;
			cr.addChild(ci::JsonTree("corner", i));
			cr.addChild(ci::JsonTree("x", corner.x));
			cr.addChild(ci::JsonTree("y", corner.y));

			corners.pushBack(cr);
		}
		warp.pushBack(corners);
		json.pushBack(warp);
	}
	return json;
}
Exemplo n.º 5
0
void JsonBag::save() const
{
	CI_ASSERT( fs::is_regular_file( mJsonFilePath ) );

	JsonTree doc;
	for( auto& group : mItems ) {
		JsonTree jsonGroup = JsonTree::makeArray( group.first );
		for( const auto& item : group.second ) {
			item.second->save( item.first, &jsonGroup );
		}
		doc.pushBack( jsonGroup );
	}
	doc.addChild( JsonTree{ "version", mVersion } );
	doc.write( writeFile( mJsonFilePath ), JsonTree::WriteOptions() );
}
void TextureSequenceOptimizer::saveJson( const fs::path& path )
{
    fs::path jsonPath = path;
    jsonPath.append("sequence.json");
    
    //save the offsets for each image into a json file
    JsonTree doc = JsonTree::makeObject();
    
    JsonTree size = JsonTree::makeObject();
    size.pushBack(JsonTree("width",  mOriOutline.getWidth()  ));
    size.pushBack(JsonTree("height", mOriOutline.getHeight() ));
    doc.pushBack(size);
    
    JsonTree sequence = JsonTree::makeArray("sequence");
    for (int i = 0; i < mTrimMaxAreas.size(); i ++) {
        JsonTree curImage = JsonTree::makeObject();
        curImage.pushBack(JsonTree("x", mTrimMaxAreas[i].x1));
        curImage.pushBack(JsonTree("y", mTrimMaxAreas[i].y1));
        curImage.pushBack(JsonTree("fileName", mFileNames[i] ));
        sequence.pushBack(curImage);
    }
    doc.pushBack(sequence);
    doc.write( jsonPath, JsonTree::WriteOptions());
}
Exemplo n.º 7
0
	void PretzelGlobal::saveSettings(fs::path settingsPath){
		fs::path appPath = settingsPath;

		if (appPath.string() == ""){
			appPath = getAppPath() / "guiSettings";

			if (!fs::exists(appPath)){
				CI_LOG_W( "Pretzel :: " ) << appPath << " does not exist. Creating it.";
				fs::create_directory(appPath);
			}
			appPath /= "settings.json";
		}

		JsonTree pSettings = JsonTree::makeObject("pretzelSettings");
		std::string tmp;
		for (int i = 0; i < mParamList.size(); i++){
			switch (mParamList[i].type){
                case _FLOAT:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, toString(*(float*)mParamList[i].value)));
                    break;
                }case _INT:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, toString(*(int*)mParamList[i].value)));
                    break;
                }case _BOOL:{
                    tmp = ((*(bool*)mParamList[i].value) == true) ? "1" : "0";
                    pSettings.pushBack(JsonTree(mParamList[i].name, tmp));
                    break;
                }case _STRING:{
                    pSettings.pushBack(JsonTree(mParamList[i].name, (*(std::string*)mParamList[i].value)));
                    break;
                }case _VEC2:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("x", toString(((vec2*)mParamList[i].value)->x)) );
                    tt.pushBack( JsonTree("y", toString(((vec2*)mParamList[i].value)->y)) );
                    pSettings.pushBack( tt );
                    break;
                }case _VEC3:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("x", toString(((vec3*)mParamList[i].value)->x)) );
                    tt.pushBack( JsonTree("y", toString(((vec3*)mParamList[i].value)->y)) );
                    tt.pushBack( JsonTree("z", toString(((vec3*)mParamList[i].value)->z)) );
                    pSettings.pushBack( tt );
                    break;
                }case _COLOR:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("r", toString(((Color*)mParamList[i].value)->r)) );
                    tt.pushBack( JsonTree("g", toString(((Color*)mParamList[i].value)->g)) );
                    tt.pushBack( JsonTree("b", toString(((Color*)mParamList[i].value)->b)) );
                    pSettings.pushBack( tt );
                    break;
                }case _COLORA:{
                    JsonTree tt;
                    tt = tt.makeArray(mParamList[i].name);
                    tt.pushBack( JsonTree("r", toString(((ColorA*)mParamList[i].value)->r)) );
                    tt.pushBack( JsonTree("g", toString(((ColorA*)mParamList[i].value)->g)) );
                    tt.pushBack( JsonTree("b", toString(((ColorA*)mParamList[i].value)->b)) );
                    tt.pushBack( JsonTree("a", toString(((ColorA*)mParamList[i].value)->a)) );
                    pSettings.pushBack( tt );
                    break;
                }default: {
                    break;
                }
			}
		}

		JsonTree root;
		root.pushBack(pSettings);
		root.write(appPath, JsonTree::WriteOptions());
        
        signalOnSettingsSave.emit();
	}
Exemplo n.º 8
0
void JsonTestApp::mouseDown( MouseEvent event )
{

    JsonTree doc;
    JsonTree library = JsonTree::makeObject( "library" );
    JsonTree album = JsonTree::makeArray( "album" );

    album.pushBack( JsonTree( "musician", string( "Sufjan Stevens" ) ) );
    album.pushBack( JsonTree( "year", string( "2004" ) ) );
    album.pushBack( JsonTree( "title", string( "Seven Swans" ) ) );

    JsonTree tracks = JsonTree::makeArray( "tracks" );

    for ( int32_t i = 0; i < 6; i ++ ) {

        JsonTree track;
        track.pushBack( JsonTree( "id", i + 1 ) );

        JsonTree title;
        switch ( i ) {
        case 0:
            title = JsonTree( "title", "All the Trees of the Field Will Clap Their Hands" );
            break;
        case 1:
            title = JsonTree( "title", "The Dress Looks Nice on You" );
            break;
        case 2:
            title = JsonTree( "title", "In the Dev Hole's Territory" );
            break;
        case 3:
            title = JsonTree( "title", "To Be a Clone With You" );
            break;
        case 4:
            title = JsonTree( "title", "To Be Removed" );
            break;
        case 5:
            title = JsonTree( "title", "To Be Removed" );
            break;
        }

        track.pushBack( title );
        tracks.pushBack( track );

    }

    for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ++trackIt ) {
        if ( trackIt->getChild( "id" ).getValue<int>() == 3 ) {
            JsonTree track;
            track.pushBack( JsonTree( "id", 3 ) );
            track.pushBack( JsonTree( "title", "In the Devil's Territory" ) );
            tracks.replaceChild( trackIt, track );
        }
    }

    JsonTree track;
    track.pushBack( JsonTree( "id", 4 ) );
    track.pushBack( JsonTree( "title", "To Be Alone With You" ) );
    tracks.replaceChild( 3, track );

    tracks.removeChild( 4 );

    for ( JsonTree::Iter trackIt = tracks.begin(); trackIt != tracks.end(); ) {
        if ( trackIt->getChild( "id" ).getValue<int>() == 6 ) {
            trackIt = tracks.removeChild( trackIt );
        } else {
            ++trackIt;
        }
    }

    album.pushBack( tracks );
    library.pushBack( album );
    doc.pushBack( library );

    console() << doc;

    doc.write( writeFile( getDocumentsDirectory() + "testoutput.json" ), false );

}