Visual in callable library

Questions and problems about using polymake go here.
sebasguts
Posts: 17
Joined: 07 Nov 2011, 09:59

Visual in callable library

Postby sebasguts » 01 Mar 2013, 14:20

Dear all,

when trying to save the output of the VISUAL-Method in C++, I constantly get errors ("input value is not an Object"). Is VISUAL not returning an perl::Object? A short piece of code is attached, where you can see the error.

Best wishes,
Sebas

Part 1: visualtest.cc
#include <polymake/Main.h>
#include <polymake/Matrix.h>
#include <polymake/SparseMatrix.h>
#include <polymake/Rational.h>
using namespace polymake;
int main(int argc, const char* argv[]) {
try {
const int dim = 4;
Main pm;
pm.set_application("polytope");
perl::Object* p = new perl::Object("Polytope<Rational>");
p->take("VERTICES") << 3*unit_matrix<Rational>(dim);
perl::Object q = p->CallPolymakeMethod("VISUAL");
} catch (const std::exception& ex) {
std::cerr << "ERROR: " << ex.what() << endl; return 1;
}
return 0;
}

Part2: Makefile
PM_INC := $(shell polymake-config --includes)
PM_CFLAGS := -fPIC -DPOLYMAKE_DEBUG=0
PM_LIBS := $(shell polymake-config --libs)
PM_LDFLAGS := $(shell polymake-config --ldflags)

CFLAGS += -march=native
LDFLAGS += -Wl,-rpath,-lpolymake -lxml2


all: visualtest

.o: visualtest.cc
g++ -o visualtest.o -c -I. ${PM_INC} ${PM_CFLAGS} ${CFLAGS} visualtest.cc

visualtest: visualtest.o
g++ -o visualtest visualtest.o ${PM_LDFLAGS} ${PM_LIBS} ${LDFLAGS}

Sorry for copying the files. It says such attachments are not allowed :(.

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: Visual in callable library

Postby gawrilow » 02 Mar 2013, 23:16

Is VISUAL not returning an perl::Object?
Well, it's indeed a confusing naming. The C++ class perl::Object is written to hold the so called "big objects" like Polytope, Fan, SimplicialComplex, or Ideal. They are indeed implemented as perl objects, but their distinguishing trait is that they possess properties, rules, user methods, attachments, etc. Therefore the C++ class perl::Object offers corresponding methods like give(), take(), add(), attach(), etc.

Nothing of this would be applicable to the result of VISUAL. It is a mere container of auxiliary data prepared for visualization back-ends. Usually the result of VISUAL is even discarded (that is, VISUAL is called in void context) which immediately starts the visualization program and starts rendering. Why do you want to store the result in your client? Can't you just use VoidCallPolymakeMethod?

sebasguts
Posts: 17
Joined: 07 Nov 2011, 09:59

Re: Visual in callable library

Postby sebasguts » 03 Mar 2013, 16:40

I want to pass the result to the sketch-method.
I think I can do this in one command, using VoidCallPolymakeMethod, but it might be a bit long, but I will try this.

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: Visual in callable library

Postby gawrilow » 03 Mar 2013, 19:54

No, you can't. sketch is not a method, it is a free function.

I'm surprised that you are trying to do such things from a C++ program. Usually producing pictures, especially with a fixed visualization back-end, is something I would expect to see in a script. Probably you have invented a new family of use cases I hadn't initially in mind. At any rate, now your desire can't be realized without extending the callable library API.

sebasguts
Posts: 17
Joined: 07 Nov 2011, 09:59

Re: Visual in callable library

Postby sebasguts » 04 Mar 2013, 11:06

Turns out I can, doing it like this:

VoidCallPolymakeFunction( "sketch", p->CallPolymakeMethod("VISUAL"), PolymakeOptions("File", "sketchtest.sk") );

I think I can life with this for now, but I would really prefer if it is possible to store the visual objects, for example for easier trying different angles. But this is not important. Thank you very much for helping :).

User avatar
gawrilow
Main Author
Posts: 423
Joined: 25 Dec 2010, 17:40

Re: Visual in callable library

Postby gawrilow » 04 Mar 2013, 23:13

But still, I'm wondering why are you doing all this in a C++ program and not in a script. The C++ clients and callable library were invented for other purposes. In a script, you can try out all possible angles, colors, styles, etc. in an instant. Do you simply abhor perl?


Return to “Helpdesk”