Message Boards Message Boards

0
|
4389 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Add a Graphics Directive?

Anonymous User
Anonymous User
Posted 7 years ago

I have two questions both about the same thing.

One: xLine[{}] - how can i add it as a Graphics (directive). I can Unprotect and modify it, but I want to create a NEW directive called xLine["",{}]. i add it to SystemSystemGraphics` and look for attributes that might help: but i always get a nefarious error message: "xLine is not a Graphics or Graphics Directive"

Two: How to make a function, lets say "cLine[][" that does what Line[[ does.

In: Line[{{0,0},{0,1}}
Out: Line[{{0,0},{0,1}}

what's special about Line is it returns itself un-evaluated WITHOUT recursing (perhaps by /; rule it has no definition until rendering, i have no idea). the other obvious thing that's special is: Graphics befriends it automatically by some attribute that cannot be seen?

what i'm doing is a little more involved but un-important really

Three: TO add a NEW Import[]; I made a (minimal) Import and Export for image format "MTV". Again i tried unprotecting but Import balked my function was a member. if i could tell Image[] the expr that reads/writes the disk image header i wouldn't need import/export. but Image[] is great compared to RasterArray - worth the time and money of upgrading old code to use it even. It describes and holds images very well.

POSTED BY: Anonymous User
6 Replies

Wouldn't it be much easier to define your own Graphics like:

MyGraphics[gr_, stuff___] := Graphics[DeleteCases[gr, MyLine[___], \[Infinity]], stuff]

So you can manipulate your primitives and so on, but once you show it using MyGraphics it would be ignored...

POSTED BY: Sander Huisman
Anonymous User
Anonymous User
Posted 7 years ago

I'm sorry. The stack exchange faces example is a GOOD example because it shows (part of) how Wolfram likes to see a well finished Graphic. I was right about Import as far as i know.

I was wrong that my Graphic example "worked where the other one didn't". More accurately today I'll say: the stack exchange example was not pertinent as to "is not a Graphic primitive or a Directive". However neither was my example because it either disables Graphics by either preventing rendering OR it will be forced to become {} to avoid the message (same problem).

What I was (am) trying to do is to have a function that Graphics IGNORES. It's for pre and post processing of Graphics. a simple example is this. g=={List of stuff}, g2=Graphics[g] (esp. if Normal) contains perhaps allot that g did not AND contains adjusted plot options. Features such as "Red" tag the next item to be red. I'm trying to tag a next item (with a function or symbol that contains data needed during post processing) for post-processing without having to need a lookup list (won't work, g2 is possibly totally different) or .

I'm thinking I'm going the wrong way about it, that a different Graphics[,f[],] attempt is needed or possibly alteration of the evaluation loop (a trap) is needed.

another issue is back to Line[{...}]. in Output it reflects it's own input without causing evaluation. Your example (use of MakeBoxes) may be why - but that i'm unsure of. it may also be Line simply has attributes but no definition - and Graphics somehow knows "not to complain".

it's ok. i'll just have to think about it some. i have other problems to solve in the mean-time.

it would be nice if there was a way or a function which Graphics new to ignore and did not remove from Output - even an option to yield a result without such function

thanks for your answers!

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

Unprotect[Import]; Import[ExportFoofilenameString, "MTV", opts__] := ImportMTV[ImportFoofilename, opts]; Protect[Import];

ImportMTV[foo,opts__]:=(* read it, Return[data], optionally check opts*)

Import["r.orig.ray.out", "TextDimRGB"] // Graphics // Show

^^ works

and again i must have tried it before and not seen something simple i typed in wrong: i had gotten the message "is not an Import type", thus asked the question.

I found that http://reference.wolfram.com/language/tutorial/DevelopingAnImportConverter.html#52861258 while useful does not state when this new functionality was introduced, and that it does not work with older versions of mathematica (creates a forced upgrade situation). Infact I'm not sure what it does except to create an un-necessary dependancy on a higher version. Am I wrong?

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

forgot to say: the circle face DOES NOT WORK. If one uses anything other than Graphics primatives or directives in create, it fails with the message "is not a type of graphics"

the example of the circle face was neat though - MakeBoxes is important to know of and i had no idea TypeSet`MakeBoxes would work in places MakeBoxes would not !!

difficult to get help yes and no. Mathematica 4.0 documented it and included the code for it for all to see - and earlier versions had even more of Mathematica in .m format. the Wolfram Library still has many .m to find (to help old notebooks to work). But as for understanding it.

it can be hard to remember pertinent things when the sun is moving and one is "stuck" waiting for a soln.

John M. Novak, Roman Meader are good code writers. /usr/local/mathematica/AddOns/StandarPackages/Graphics.m

In[2230]:= Unprotect[Graphics]

Out[2230]= {"Graphics"}

In[2231]:= Graphics[{___, f[x_], ___}] := If[y, Print@x, {}]

In[2232]:= Protect[Graphics]

Out[2232]= {"Graphics"}

In[2235]:= g = Graphics[{f["hi"]}]

Out[2235]= If[y, Print["hi"], {}]

in the above Graphics did not complain that f[] is not a type of Graphics

however what must have happened is that i tried an example f[] (earlier before asking question) and believed it hadn't worked ( probably forgetting parenthesis or something which caused a pattern miss and me to be mislead to think it hadn't worked)

btw thank you for the URL on Import that helped allot. I wouldn't have though looking for it in Tutorials - I'm new to Mathematica 11.0 and still tend to use it as if it's Mathematica 4.0 (which has no guides to find)

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

I was just going to pat you on the back and warn you that stack exchange is the #1 spreader of obstruction and bad advice - i've been kicked off stack exchange for correcting bad advice where i could %100 prove in court I had the right answer.

However you did miss something. Graphics will not complain about a user created Symbol if it is composed %100 of Mathematica graphics directives because when it evaluates it expands to only Graphics Directives.

To be more clear I want to make a function that works line Line[{}] (see above) that generates NO graphics (and also does not obstruct Show in any manner) yet by does do math and have output whenever it DOES NOT appear between Graphics[brackets]

Also Import. I don't think your example would ADD a new file format for Import/Export which is a similar task (however on that one i want to add a normal function that works expectedly, not a hybrid).

thank you

POSTED BY: Anonymous User

Line doesn't do anything. It just displays in a certain way when inside Graphics.

Note that it is called a graphics primitive, not a directive. Things that control styling, like PointSize[0.1], are directive.

Creating new graphics primitives is not something that is normally necessary, and I do not recommend it. Instead, create a function which returns the graphics that you want, constructed out of built-in primitives.

If you still want to do it, here's how:

It requires using undocumented functionality that you will find it difficult to get help with.


Regarding your other question, here is the documentation on creating custom importers. No unprotecting is needed.

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract