How to access VTK's class enumeration field - c++

I'm having problems trying to acces a enumeration field in my following code.
vtkSmartPointer<vtkGenericDataObjectReader> reader =
vtkSmartPointer<vtkGenericDataObjectReader>::New();
reader->SetFileName(file_name);
reader->Update();
vtkSmartPointer<vtkDataObject> vtk_data = reader->GetOutput();
vtkSmartPointer<vtkFieldData> points =
vtk_data->GetAttributesAsFieldData(vtkDataObject::AttributeTypes.POINT);
//points->PrintSelf(cout, 0);
However I get the following error:
error: expected primary-expression before ‘int’
vtk_data->GetAttributesAsFieldData(int(vtkDataObject::AttributeTypes.POINT));

For me ( using GCC 8.1 ) the following compiles without any error.
#include <vtkDataObject.h>
int main(){
auto a = vtkDataObject::AttributeTypes::POINT;
return 0;
}

Related

flatbuffers sample gives non-standard syntax errors on compile in VS2017

I have been trying to reproduce something even simpler than the C++ sample in: https://github.com/google/flatbuffers/blob/master/samples/sample_binary.cpp
But I am getting some compile errors in VS2017 on the lines
//auto pos = compare->pos;
//auto two = compare->deviceType;
//auto desc = compare->description;
If I comment them out, it compiles and runs. If not, then I get the following errors:
Severity Code Description Project File Line Suppression State
Error C3867 'PNT::PseudoGPS::pos': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 50
Error C3867 'PNT::PseudoGPS::deviceType': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 51
Error C3867 'PNT::PseudoGPS::description': non-standard syntax; use '&' to create a pointer to member LinkWareMessageBus d:\source\linkwaremessagebus\linkwaremessagebus.cpp 52
Here is the definition of my FBS object:
// Example IDL file for the PNT Schema
namespace PNT;
enum DeviceType:byte { IMU, VAN, GPS, MAGNAV, SOOP }
struct Vec3 {
x:float;
y:float;
z:float;
}
table PseudoGPS {
pos:Vec3;
deviceType:DeviceType = GPS;
description: string;
}
root_type PseudoGPS;
And here is the code that creates the FB object and then tries to access things (I am just exploring at this point, the code is not done).
flatbuffers::FlatBufferBuilder builder(1024);
auto position = PNT::Vec3(4.0, 5.0, 6.0);
auto description = builder.CreateString("Magnetic Postion");
auto msg = PNT::CreatePseudoGPS(builder, &position, PNT::DeviceType_MAGNAV, description);
builder.Finish(msg);
uint8_t *buf = builder.GetBufferPointer();
int size = builder.GetSize();
auto compare = PNT::GetPseudoGPS(buf);
auto pos = compare->pos;
auto two = compare->deviceType;
auto desc = compare->description;
compare->pos refers to an accessor function, try appending ()

Cannot compile (Not declared & Expected Primary Expression)

So bellow follows a function that will then be called for a main program. My problem is, if I do not declare challInfo as a struct, upon compiling, it will return:
ERROR on page PhotoPoints at line 5, col 21: ‘challInfo’ was not declared in this scope
Meanwhile, if I do declare it (as it is bellow) it returns:
ERROR on page PhotoPoints at line 5, col 30: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 7, col 52: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 28: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 60: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 8, col 109: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 31: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 66: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 9, col 118: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 14, col 35: expected primary-expression before ‘.’ token ERROR on page PhotoPoints at line 14, col 57: expected primary-expression before ‘.’ token
I have been looking around the internet, including Stack Overflow, and it always seems the answer to this is specific to each case. I admit I'm lost. Can you help?
float PhotoPoints() {
struct challInfo;
bool isFacingOther();
bool sphereInDark();
bool isCameraOn = challInfo.camera.cameraOn;
bool isFacingOtherResult = isFacingOther();
bool isOppNotInDarkZone = !sphereInDark(challInfo.other.zrState);
bool myMirror = challInfo.me.mirrorTime != 0 && challInfo.me.mirrorTime + ITEM_MIRROR_DURATION > challInfo.currentTime;
bool otherMirror = challInfo.other.mirrorTime != 0 && challInfo.other.mirrorTime + ITEM_MIRROR_DURATION > challInfo.currentTime;
float picturePointValue = 0;
if (isCameraOn && isFacingOtherResult && isOppNotInDarkZone && !myMirror)
{
float bet[3], distance;
mathVecSubtract(bet, challInfo.me.zrState, challInfo.other.zrState, 3);
distance = mathVecMagnitude(bet, 3);
if (distance < PHOTO_MIN_DISTANCE) {
DEBUG(("Not a good shot: too close to the other satellite | "));
return 0.0;
}
picturePointValue = 2.0 + 0.1/(distance - PHOTO_MIN_DISTANCE + 0.1);
if(otherMirror){
picturePointValue = 0;
DEBUG(("Not a good shot: Opposing mirror active |"));
}
}
else if(!isCameraOn){
DEBUG(("Not a good shot: camera off |"));
}
else if(myMirror){
DEBUG(("Not a good shot: my mirror's in the way |"));
}
else if(!isFacingOtherResult) {
DEBUG(("Not a good shot: not facing the other satellite | "));
}
else if(!isOppNotInDarkZone){
DEBUG(("Not a good shot: opponent in dark zone |"));
}
return picturePointValue;
}
You have an error here for every time you have referenced a member of challInfo. You need to include a full declaration so that the compiler can tell what is inside of the struct, nut simply that it is a struct. You have only provided a forward declaration.
struct challInfo;
Should have a definition like:
// Define your camera object
struct Camera {
bool isCameraOn;
}
// Define the object type of challInfo
struct PhotographyInfo {
Camera camera
}
then you can use the object:
PhotographyInfo challInfo{};
challInfo.camera = Camera{true};
you define a struct challInfo then after assign the bool isCameraOn to a data member of that struct. Here is the problem I think you are a bit confused about structs. A struct is in many ways like a class. Where for example I could put something like this in a header file with other class definitions.
struct Example_struct{
int data_mem_a;
bool data_mem_b;
}
Then perhaps use this struct in a class prototype
class example_class{
private:
example_struct struct_instance;
public:
bool get_a_from_struct(){return struct_instance.data_mem_a;};
In your case you would want to make sure that the challInfo struct is defined somewhere, and then declare an instance of it.
challInfo CI;
bool isCameraOn = CI.camera.caneraOn;

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory

Need Help.
I am doing work on facial emotion recognition in VS2010 using OPENCV and FANN Library. It Build successfully but running it give following error:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at fann_run(fann* , Single* )
at main() in c:\down\uf-lightbot-read-only\src\emo_test.cpp:line 24
at mainCRTStartup()
Code is as follows:
#include <iostream>
#include "fann.h"
using namespace std;
int main()
{
fann_type *calc_out;
fann_type input[10];
struct fann *ann = fann_create_from_file("emotions.net");
input[0] = 0.87;
input[1] = 1.20;
input[2] = 1.03;
input[3] = 1.45;
input[4] = 0.96;
input[5] = 1.00;
input[6] = 0.98;
input[7] = 1.486;
input[8] = 1.042;
input[9] = 1.016;
calc_out = fann_run(ann, input);
cout<<calc_out[0]<<" "<<calc_out[1]<<" "<<calc_out[2]<<" "<<calc_out[3]<<endl;
fann_destroy(ann);
return 0;
}
Can any body help me what is the problem ?
Waiting for guidance. . .
Thanks.
Problem solved. Emotion.net contain doesn't contain some of required variables.

Resolve c++ pointer-to-member error in VS 2003

I have a c++ program that I'm trying to port from VS98 to VS2003 (incremental steps). One error that occurs throughout is "Error 2275"
For instance: k:\RR\chart\chartdlg.cpp(2025): error C2475: 'CRrDoc::cFldFilter' : forming a pointer-to-member requires explicit use of the address-of operator ('&') and a qualified name
The offending code is shown below:
void CDataPage::OnBtnLabelField()
{
FLDID fid ;
LPMFFIELD f ;
CRrApp *pApp = (CRrApp *)AfxGetApp();
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CRrDoc *pDoc = (CRrDoc *)pFrame->GetActiveDocument();
CSelectFieldDlg dlg;
//**************************************************
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter;
//dlg.ck = CRrDoc->*zcFldFilter;
//**************************************************
dlg.ck = pDoc->cFldFilter ;
dlg.TitleTextID = IDS_2676;
fid = (FLDID)dlg.DoModal();
if (fid != NOID)
{
f = pDoc->m_pComposite->mfbyndx(fid);
// find index
int i, iCount;
iCount = m_lboxLabel.GetCount();
for (i = 0; i < iCount; i++)
{
if(fid == m_lboxLabel.GetItemData(i))
{
m_lboxLabel.SetCurSel(i);
OnSelchangeComboLabel();
}
}
}
}
I tried handling it according to a Microsoft page: But that just generated a set of other problems (the commented code between the asterisks). Note that I also commented out the following line:
dlg.ck = pDoc->cFldFilter
Unfortunately, this leads to a new error: k:\RR\chart\chartdlg.cpp(2022): error C2440: 'initializing' : cannot convert from 'BOOL (__cdecl )(LPMFFIELD)' to 'BOOL CRrDoc:: '
The definition in the .H file looks like:
public:
static BOOL cFldFilter(LPMFFIELD f);
Any ideas how to handle the pointer-to-member issue?
since you have:
static BOOL CRrDoc::cFldFilter(LPMFFIELD f);
its type is not a member variable but a function:
//BOOL CRrDoc::*zcFldFilter = &CRrDoc::cFldFilter; // doesn't work
BOOL (*zcFldFilter)(LPMFFIELD) = &CRrDoc::cFldFilter; // works
Since dlg.ck is of a correct type, you should do
dlg.ck = &CRrDoc::cFldFilter;

V8 compile error for basic example

I am trying to compile the hello world example for V8, and I keep running into a compile time error. Here is the code:
#include <v8/src/v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a string holding the JavaScript source code.
String source = String::New("Hi");
// Compile it.
Script script = Script::Compile(source) ;
// Run it.
Value result = script->Run();
// Convert the result to an ASCII string and display it.
String::AsciiValue ascii(result) ;
printf("%s\n", *ascii) ;
return 0;
}
This is the compile error:
error: conversion from ‘v8::Local<v8::String>’ to non-scalar type ‘v8::String’ requested
The error is for line 8 where it says: String source = String::New("Hi");
I have tried google'ing this error senseless, and cannot seem to find a fix for it that makes sense. Any ideas?
I have tried both:
svn checkout http://v8.googlecode.com/svn/trunk/ v8
and
svn checkout http://v8.googlecode.com/svn/branches/bleeding_edge/ v8
and get the same error for both.
Based on the error message, try:
Local<String> source = String::New("Hi");
try this code:
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<String> source = String::New("'Hello' + ', World!'");
Handle<Script> script = Script::Compile(source);
TryCatch trycatch;
Handle<Value> result = script->Run();
if ( result.IsEmpty() ) {
Handle<Value> excep = trycatch.Exception();
String::AsciiValue excep_str(excep);
printf("%s\n",*excep);
} else {
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
}
context.Dispose();
return 0;