I am getting json data from server like this -
if (response->isSucceed()) {
log("Get success");
std::vector<char>* buffer = response->getResponseData();
std::string res;
res.insert(res.begin(), buffer->begin(), buffer->end());
log("res: %s", res.c_str());
rapidjson::Document d;
d.Parse<0>(res.c_str());
if(d.IsObject()){
log("true"); // print the value of obtaining hello
}
F = d["F"].GetString();
W = d["W"].GetString();
T = d["T"].GetString();
Fp = d["Fp"].GetString();
Wp = d["Wp"].GetString();
Tp = d["Tp"].GetString();
}
Now i want to display that value of “F” using label…Value of F is integer number.
So i do this -
foodnumber = Label::createWithTTF(F, "fonts/A little sunshine.ttf", 40 );
foodnumber->setColor(Color3B(109,61,23));
foodnumber->setPosition( Vec2(foodtitle->getPositionX() + foodtitle-
>getContentSize().width/4 + origin.x, foodtitle->getPositionY() + origin.y)
);
this->addChild( foodnumber);
It doesn’t print the value…
The value in the F is Number.
But when i log the value, it gets logged right, but it doesn’t get displayed on app as label.
Thank you
Related
Can I get some examples about pointclouds with ARCore? I really search it for days.
Currently I am working on an application similar to this one:This app
Has the feature to view pcl and save files in .ply format
Thanks
The HelloARSample app renders pointcloud in a scene. You can get the coordinates for each point and save them manually in a .ply format.
To get a point cloud, you can create a float buffer and add the points from each frame.
FloatBuffer myPointCloud = FloatBuffer.allocate(capacity);
Session session = new Session(context);
Frame frame = session.update();
try (PointCloud ptcld = frame.acquirePointCloud()) {
myPointCloud.put(ptcld.getPoints());
}
The float buffer saves the points like [x1,x1,z1,confidence1, x2,x2,z2,confidence2, ...].
I havent looked at .ply file struckture, but if you want to save it to a .pcd file, you must create a header, then insert a point per line. Here is a detailed explanation on how to do it.
I did it like this
private boolean savePointCloudFile() {
String data = "";
String fileName = "pointCloud";
int points = 0;
String holder = "";
// Write the point cloud data by iterating over each point:
for (int i=0; i<pointCloud.position(); i+=4) {
data += pointCloud.get(i) + " " + // x
pointCloud.get(i + 1) + " " + // y
pointCloud.get(i + 2) + " " + // z
pointCloud.get(i + 3) + "\n"; // confidence
points = i;
}
points = points / 4 - 10; // Removed last 10 points to prevent errors in case that I lost points
// Write file header
data = "# .PCD v.7 - Point Cloud Data file format\n" +
"VERSION .7\n" +
"FIELDS x y z rgb\n" + // confidence represented by rgb
"SIZE 4 4 4 4\n" + // you only have 3 values xyz
"TYPE F F F F\n" + // all floats
"COUNT 1 1 1 1\n" +
"WIDTH " + points + "\n" +
"HEIGHT 1\n" +
"VIEWPOINT 0 0 0 1 0 0 0\n" +
"POINTS " + points + "\n" +
"DATA ascii \n" + data;
//BufferedWriter out = new BufferedWriter(new FileWriter(new File(new File(Environment.getExternalStoragePublicDirectory(
// Environment.DIRECTORY_DOCUMENTS), fileName + ".pcd"));
try {
File file = new File(context.getExternalFilesDir(null), fileName +".pcd");
FileOutputStream stream = new FileOutputStream(file);
file.createNewFile();
//FileOutputStream out = new FileOutputStream(file);
stream.write(data.getBytes());
stream.close();
Log.i("SUCCESS", "File saved successfully in " + file.getAbsolutePath());
return true;
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
return false;
}
}
You should save the file from within a separate thread as it may cause a timeout error, because it takes too long to save so many points to a file.
You should get a file similar to this
# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1
WIDTH 3784
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 3784
DATA ascii
0.068493545 -0.18897545 -0.6662081 0.007968704
0.26833203 -0.18425867 -1.5039357 0.02365576
0.19286658 -0.2141684 -1.58289 0.038087178
0.070703566 -0.17931458 -0.69418937 0.016636848
0.044586033 -0.18726173 -0.6926071 0.024707714
0.04002113 -0.20350328 -0.68689686 0.018577512
0.029185327 -0.18594348 -0.73340106 0.12292312
0.0027626567 -0.20299685 -1.5578543 0.15424652
-0.031320766 -0.20478198 -0.70128816 0.13745676
-0.06351853 -0.20185146 -0.61755043 0.15234329
-0.08655308 -0.19128543 -0.6776818 0.170851
1.0159657 -0.41043654 -6.8713074 0.05946503
-0.031778865 -0.20536968 -1.5218562 0.15976532
-0.09223208 -0.19543779 -0.61643535 0.12331226
0.02384475 -0.20319816 -1.7497014 0.15273231
-0.10013421 -0.19931296 -0.5924832 0.16186734
0.49137634 -0.09052197 -5.7263794 0.16080469
To viaualize the point cloud you can use pcl_viewer or Matlab. In Matlab I just typed
ptCloud = pcread('pointCloud.pcd');
pcshow(ptCloud);
In my app i send four basic commands to OBD ports and get back hex data...
I don't know why if i send the command:
ME: 010c
Car: 10c410c0000
Why the message don't start with 4?
And get only 410c and the data that the obd receive from car?
I use this method for manage hex response and convert it to human readable data, and RawData is a String that take the message and clear all space, like this
41 0c 00 00 = 410c0000
public String getCalculatedResult() {
//TODO devo convertire i dati da esadecimale a decimale ed effettuare i calcoli
int calculatedData = 0;
String dataToShow = null;
//Log.d("ObdCommand", "rawData: " + rawData.substring(3));
calculatedData = Integer.parseInt(rawData.substring(7), 16);
if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
Pattern.CASE_INSENSITIVE).matcher("410D").find()){
Log.d("ObdCommand", "dentro 410D: ");
//Velocità veicolo km/h
dataToShow = String.valueOf(calculatedData) + " Km/h";
Log.d("ObdCommand", "rawData: " + dataToShow);
}else if (Pattern.compile(Pattern.quote(rawData.substring(3,4)),
Pattern.CASE_INSENSITIVE).matcher("410C").find()){
Log.d("ObdCommand", "dentro 410C: ");
//Giri minuto veicolo rpm
calculatedData = calculatedData/4;
dataToShow = String.valueOf(calculatedData) + " rpm";
}else if (rawData.substring(3).startsWith("4105")){
//Temperatura refrigetante C°
calculatedData = calculatedData - 40;
dataToShow = String.valueOf(calculatedData) + " C°";
}else if (rawData.substring(3).startsWith("4151")){
//Tipo di carburante
if (rawData.substring(7).startsWith("09")){
//Benzina
dataToShow = "Benzina";
}else if (rawData.substring(7).startsWith("0d")){
//Metano
dataToShow = "Metano";
}
}
return dataToShow;
}
I use the rawData.substring(7) because 3 is the characters that i tell at the start of post
10c
And the other 4 are
410c
So i get only the value that i need to decimal... but sometimes i get outof bound....
Someone have some idea to get this with no problems?
Thanks
when i generate a problem or number in this case, it seems to always come out as 0, when it should be generating a number between 0 and the value AD given. which in this case is 0 through 11, but only generates a 0 every time. for some reason the AD int is returning as 1 when i log it to the debug console. any help?
Double d = Math.random() * Max1;
O1 = d.intValue();
Log.d("BasicsPractice.java","the GenerateOperation function generated : " + O1 + " : as the number to determin the operation to be built");
if(O1 == 0) {
if(AddP == true) {
int AD = DM.AddDiff + 1;
Double d1 = Math.random() * AD;
A1 = d1.intValue();
Log.d("BasicsPractice.java","the first Addition number generated was: " + A1);
Double d5 = Math.random() * AD;
A2 = d5.intValue();
Log.d("BasicsPractice.java","the second Addition number generated was: " + A2);
Output = A1 + " + " + A2;
Log.d("BasicsPractice.java","the outputted problem was: " + Output);
OutputToProblemView();
}
Math.random() returns a number from 0.0 to 1.0. So you need to convert it into int.
Try this out.
Math.floor(Math.random()*12);
This will generate numbers between 0 to 11.
I have a SQLDB with table of field REAL. In my layout I have set its field size to allow only 8+2 digits. In my object I have used the data-type of the field as "float".
qs[0] = "CREATE TABLE " + RELATION_TABLE_NAME + "(id TEXT PRIMARY KEY, name TEXT NOT NULL, startBal REAL NOT NULL, currentBal REAL NOT NULL);";
<EditText android:text="" android:id="#+id/relCurrBalTxt" style="#style/EditTextStyle"
android:inputType="numberDecimal" android:maxLength="11" android:hint="12345678.99" />
I entered value "87654321.99" in my editText and clicked save. It populates the object
// Send the data to object
rowData.setValue(2, Float.parseFloat(sbalTxt.getText().toString()));
// In object, this is how I save it
this.setCurrentBalance( ((Float)value).floatValue() ); // value is Object type
// Saving data in ContenteValues to save to DB
// LOG Rcvd from Object while Saving CurrBal: 8.765432E7
values.put("currentBal", new Float(rowData.getValue(3).toString()));
On saving, it directly show the table with the updated data. While showing it in table I use DecimalFormat to make sure it is shown in proper manner :
field_type = r.getFieldType(field);
// Get Data
str = r.getValue(field).toString();
// Format accordingly
if(field_type.equals(DBRow.DOUBLE_TYPE) || field_type.equals(DBRow.FLOAT_TYPE)) {
double douValue = Double.parseDouble(str);
//NumberFormat nf = NumberFormat.getNumberInstance(Locale.ITALY);
//DecimalFormat df = (DecimalFormat) nf;
DecimalFormat df = new DecimalFormat();
df.applyPattern("##,###,###.##");
df.setGroupingUsed(true);
str = df.format(douValue);
// Log.v("DF", "While Showing in Table : double = " + douValue + " String = " + str);
}
((TextView) tr.getChildAt(field)).setText(str);
HERE it showed me the value : 8.765432E7
When I again selected that row to see the values in EditText I see : 87654320.00
How is the value changed ? In other instance also I saved the data as "50009876.99", but somehow it doesn't save .99 and makes that as .00 i.e 50009876.00.
Why things are not working correctly ? Where am I going wrong ?
Any help is highly appreciated.
*EDIT : DecimalFromat code used to display in table *
// Format accordingly
if(field_type.equals(DBRow.DOUBLE_TYPE) || field_type.equals(DBRow.FLOAT_TYPE)) {
/*
WAS USING THIS CODE TILL NOW
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
String decep = String.valueOf(dfs.getDecimalSeparator());
int index = str.indexOf(decSep);
if (index > 0) {
// If digits after decimal are more than 2
if (str.substring(index+1).length() > 2) {
str = str.substring(0, index+3);
}
}
DecimalFormat df = new DecimalFormat();
df.setGroupingUsed(true);
str = df.format(Double.parseDouble(str));
if (addRow)
create_addTextView(tr, str, true);
else
((TextView) tr.getChildAt(field)).setText(str);
*/
// DECIMALFORMAT CODE
double douValue = Double.parseDouble(str);
DecimalFormat df = new DecimalFormat();
df.applyPattern("##,###,###.##");
df.setGroupingUsed(true);
str = df.format(douValue);
if (addRow)
create_addTextView(tr, str, true);
else
((TextView) tr.getChildAt(field)).setText(str);
}
I think your problem is that you store the numbers as Float. Float does not have very good precision - it actually has only 23 binary digits of precision as seen here. This means that you can not store accurately in float 7 digits before the decimal point or even worse - 7 digits before the point and a couple after. This means that you have incorrectly chosen the type of the balance variable - you can not store in Float 8+2. I would recommend you to change the type to Double, which has significantly larger range of precision.
I am getting an unusual result when attempting to place a value in an array.
I have an array table[] of a simple class result{ int score, long time, string ID}
Intention is to have a sort of leader board.
My code happily finds the correct place to insert a new score if it is in the top 10.
int ix = 0;
int jx = 10; //
while ( ix < jx )
{
if (points > sTable[ix].points)
{
// score is higher move records down
for (jx = mNumRecords - 1; jx >ix ; jx--)
{
sTable[jx] = sTable[jx -1];
}
//now add new score
sTable[ix].score = score; // all good until here
sTable[ix].time = time;
}
ix++;
}
Problem is that when I try to insert the score using sTable[ix].score = score;
The value gets written to sTable[ix].score and also sTable[ix +1].score.
It is repeatable, it occurs at any value of ix, I have single stepped through the code and as far as I can tell the command only executes once.
Has anyone seen this before?
That because you copied the object reference to the next element in the array. You should copy the values, or create a new object:
Option A:
// score is higher move records down
for (jx = mNumRecords - 1; jx >ix ; jx--)
{
sTable[jx].time = sTable[jx -1].time;
sTable[jx].score = sTable[jx -1].score;
}
//now add new score
sTable[ix].score = score; // all good until here
sTable[ix].time = time;
Option B:
for (jx = mNumRecords - 1; jx >ix ; jx--)
{
sTable[jx] = sTable[jx -1];
}
sTable[ix] = new Result(score, time, ""); // Or however you construct the object